6
votes

I have a WinForms application that is using LocalDb. Of course on my development box, this works fine. When I deploy the application to another box, I am getting the following error message:

"A network-related or instance specific error ocurred while establishing a connection to SQL Server."

I have gone through many of the posts on Stackoverflow on this issue - most seem related to the connection string.

One of the issues I am having is that on my development box, I started a named LocalDb instance. On my install target, I am running the LocalDb installation MSI.

For the installed instance, is there a way to programmatically instantiate a named LocalDb instance or a way to connect to the default LocalDb instance?

Is it possible to programmatically instantiate a named LocalDb instance?

Or can I create a connection string that can be used to open my LocalDb database using (localdb)\v11.0;

I am also using DbContext in the development - again on the development box, LocalDb and DbContext work fine. Does the use of DbContext and EF affect the LocalDb connection string on the target box?

1

1 Answers

4
votes

There are two ways actually:

  1. LocalDBCreateInstance function from LocalDB API, for native C/C++ code and through PInvoke
  2. system.data.localdb / localdbinstances element in your application's app.config (.NET applications only, requires .NET 4.0.2 or later)