开发者

Visual Studio/C# Entity Data Model

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜