开发者

Visual Studio/C# Entity Data Model

开发者 https://www.devze.com 2023-01-25 17:53 出处:网络
I setup a EDM for a SQL database in visual studio. I set the connection string in a configuration file but my question is how I can test if the database was properly connected.

I setup a EDM for a SQL database in visual studio. I set the connection string in a configuration file but my question is how I can test if the database was properly connected.

If I put a broken connection string for the database in the config file, the program still boots and makes its way 开发者_运维知识库to the queries, then it throws an exception. How can I ensure that the string has made a successful connection or not?

Thanks


Make a call to check if the DataBase exists

using (var ctx = new BonsaiEntities())
{
   if ( ctx.DatabaseExists() ) {
   };
}
0

精彩评论

暂无评论...
验证码 换一张
取 消