I have this little method that should create a custom object called DataSource:
private static DataSource BuildDataSourceFromString(string connectionString)
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString);
DataSource dbConnection = new DataSource()
{
Source = builder.DataSource,
Catalog = builder.InitialCatalog
};
return dbConnection;
}
The main reason I use this class ( SqlConnectionStringBuilder) is to conveniently grab the directory and data source.
When I pass the Entity Framework connection string (and initializes SqlConnectionStringBuilder) to it, I get the following exception:
Keyword not supported: 'metadata'
I could start parsing the string to check and distinguish between the Entity Framework connection string and the classic one, but really want something elegant to access both of them, without code that needs to “know” about it (because I repeat them many species in my project).
:
<add name="someconnectionstring"
connectionString="metadata=res://*/DB.SomeDataModel.csdl|res://*/DB.SomeDataModel.ssdl|res://*/DB.SomeDataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=some-data-source;initial catalog=SomeCatalog;integrated security=True;MultipleActiveResultSets=True;MultiSubnetFailover=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
, :
<connectionStrings>
<add name="SomeData"
connectionString="Server=Some-Server;Database=SomeCatalog;Integrated Security=SSPI;"
providerName="System.Data.sqlclient" />
</connectionStrings>
- , ? - , SqlConnectionStringBuilder, ? , Entity Framework , ?
.