When creating and ADO.NET Entity Connection String you get something like
Assuming you have an instance of the ObjectContext
(if you are using the built-in designer, your context derives from the EF ObjectContext
class). You can cast the value of the ObjectContext.Connection
property (which is a DbConnection) to an EntityConnection
.
The EntityConnection
class has a property StoreConnection
which is the actual DbConnection
used to connect to the database. This one actually has the ConnectionString
property set to the one you are looking for.
Edit: Some sample code (Assign context to your ObjectContext):
ObjectContext context = entities;
EntityConnection entityConnection = context.Connection as EntityConnection;
if (null != entityConnection)
{
Console.WriteLine(entityConnection.StoreConnection.ConnectionString);
}