1

I am looking to parse the webconfig to extract all connections strings. From this, I am trying to build up a list of Catalogs, connection strings, and states of the db's by polling the sys.databases table to get the state.

The problem I am coming across is the 2/3 of the connection strings are entityConnectionStrings as we used dbfirst (EDMX's) to get our contexts. and the third is the integrated sqllite connection string that is auto generated when the project is built.

using ConfigurationManager.ConnectionStrings I am able to retrieve all 3 strings, but how can I tell the difference between them, or is there a way to cast the EntityConnectionStrings to SQLConnectionsStrings so I can use the SqlConnectionStringBuilder to parse the parts required

asuppa
  • 571
  • 1
  • 11
  • 27

1 Answers1

1

In order to parse EntityConnectionStrings, you can use the 2 commands below:

string entityConnectionString = ConfigurationManager.ConnectionStrings["MyDbEntities"].ConnectionString;
string providerConnectionString = new EntityConnectionStringBuilder(entityConnectionString).ProviderConnectionString;

Then use the providerConnectionString to set up a new SQLConnectionsStrings object.

This was also discussed at this link

Community
  • 1
  • 1
MayowaO
  • 380
  • 4
  • 12