How do I retrieve Entity Framework's provider-specific ConnectionString?

.net ado.net connection-string entity-framework

Question

To construct a sqlconnection object using ado.net, we often need to declare a connectionstring. If we use the entity framework, we also need to define a connectionstring.

Is it possible to get the precise provider connection string that Entity Framework uses?

Assuming the CS is defined as follows on ado.net:

"Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;"

and Entityframework ought to convert their CS format to something similar; is this possible?

I'd want to know whether it's feasible to get the precise provider connectionstring that EF generates.

How can I change a connection string from an entityframework database to a sqlserver connection string?

1
14
5/11/2013 1:10:40 AM

Accepted Answer

string entityConnectionString = ...

var builder = new EntityConnectionStringBuilder(entityConnectionString);
string providerConnectionString = builder.ProviderConnectionString;
31
5/31/2011 2:53:55 PM

Popular Answer

I figured it out:

            System.Data.EntityClient.EntityConnection c = (System.Data.EntityClient.EntityConnection)EFDBcontext.Connection;
            String S = c.StoreConnection.ConnectionString;


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow