Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get provider specific ConnectionString from Entity Framework

using ado.net tipically we need to define a connectionstring to create a sqlconnection object, and if we use the entity framework, we have to dedine a connectionstring too.

is threre any way to get the specific provider connectionstring used by entity framework?

Assuming that originally on ado.net we define the CS like:

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

and Entityframework should translate their CS format on something like that, is it possible to obtain this?

what i pretend is to know if is possible to get the specific provider connectionstring generated by EF?

How can i convert a entityframework connectionstring on a sqlserver connectionstring?

like image 787
Flavio CF Oliveira Avatar asked May 31 '11 14:05

Flavio CF Oliveira


2 Answers

string entityConnectionString = ...

var builder = new EntityConnectionStringBuilder(entityConnectionString);
string providerConnectionString = builder.ProviderConnectionString;
like image 110
Thomas Levesque Avatar answered Sep 26 '22 00:09

Thomas Levesque


Found the solution:

            System.Data.EntityClient.EntityConnection c = (System.Data.EntityClient.EntityConnection)EFDBcontext.Connection;
            String S = c.StoreConnection.ConnectionString;
like image 28
Flavio CF Oliveira Avatar answered Sep 26 '22 00:09

Flavio CF Oliveira