Get the Entity Framework Connection String

You can get the connectionstring used by EF by using the following:

MyDbContext.Database.Connection.ConnectionString

Or as mark says you can initalise the context with a sqlconnection


Here's how to get the connection string in EF 5, EF 6 and EF Core 1/EF 7.

//Entity Framework 5
myContext.Database.Connection.ConnectionString
//Entity Framework 6
myContext.Database.Connection.ConnectionString
//Entity Framework Core 1
myContext.Database.GetDbConnection().ConnectionString

For more details see - http://nodogmablog.bryanhogan.net/2016/04/entity-framework-checking-the-connection-string-of-your-context/