0

I need to support SQL Express and LocalDb in my ASP.NET application. This is a sample app for demo purposes and not a real website.

Currently the app is shipped with LocalDb connection string:

<add name="Conn" 
connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=SampleDB;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\SampleDB.mdf" 
providerName="System.Data.SqlClient" />

If user has SQL Express installed only, he must update the connection string to be:

<add name="Conn"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\SampleDB.mdf;User Instance=true"
providerName="System.Data.SqlClient" />

Is it possible to specify connection string so that both SQL Express and SQL LocalDb are supported and user do not need to update the connection string?

I can update my sample application to test Sql Express and Local DB presence and choose the required string automatically, but want to avoid this, because I need to keep the app as simple as possible with minimum code.

IT Hit WebDAV
  • 5,652
  • 12
  • 61
  • 98

1 Answers1

0

I don't think that a "universal" connection string is possible. It would defeat the purpose of the connection string, which is to provide information for a particular data store running on a particular technology.

If your problem is that you develop on LocalDB and have production in say SQL Server Express, you can take advantage of web.config transformations to select the connection string based on the environment to which you are deploying.

Jan Kratochvil
  • 2,307
  • 1
  • 21
  • 39