Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check connection to database in Entity Framework Core?

In normal entity framework I am able to check the database connectivity using dbContext.Database.Exists() but in Entity Framework Core it is not there. What is the alternative of dbContext.Database.Exists() in Entity Framework Core?

like image 441
Harsh darji Avatar asked Sep 18 '17 17:09

Harsh darji


People also ask

How do I test my EDMX connection string?

Open the edmx (go to properties, the connection string should be blank), close the edmx file again. Open the app. config and uncomment the connection string (save file) Open the edmx, go to properties, you should see the connection string uptated!!


1 Answers

You can determine whether or not the database is available and can be connected to with the CanConnect() method:

if (dbContext.Database.CanConnect())
{
    // all good
}

You can use CanConnectAsync() for asynchronous operation.

like image 141
nmur Avatar answered Sep 22 '22 00:09

nmur