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?
Check and create a LocalDB instance To do that, locate SqllocalDB.exe and run the following command in a command prompt: You will see a list of available LocalDB instances on the server. This command creates an instance of LocalDB named DEVELOPMENT by using SQL Server 2017 binaries and starts the instance.
Start LocalDB and connect to LocalDB To connect to a specific database by using the file name, connect using a connection string similar to Server=(LocalDB)\MSSQLLocalDB;Integrated Security=true;AttachDbFileName=D:\Data\MyDB1. mdf .
There are two ways actually:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With