I have made an application which uses a LocalDB, to refer to some predefined values as part of some mathematics that it does. I have created an Installer project so that when the application gets installed, a copy of the DB is sent to [ProgramData][ProductName], which is mapped as the pathway for the ConnectionString.
When I install it and run the application on my computer (out of Visual Studio), it runs exactly as I want it too - and there are no errors, warnings or messages in the code. However when I installed it on to someones else's computer (so they can play with it and point out any errors that they come across), this is where the problem comes about.
On their computer, whenever the code refers to the LocalDB they get the below Exception Message:
"A network-related or instance specific error occurred while trying to establish a connection to SQL Server" System.Data.SqlClient.SqlException (0x80131904). The error goes on to say that the LocalDB instance does not exist.
I've double checked the ProgramData folder, and can confirm that the LocalDB did get copied there during the install - and I have confirmed that the code is looking at the correct folder when trying to connect to it - I just can't figure out what is happening.
I have checked that the user has read/write access to the folder, and is a LocalAdmin on their computer.
Is anyone able to help guide me to a solution with this, please?
ConnectionString is below, if it helps:
AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Application_Name")); ConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True";
You actually can connect to a localdb instance from other machines. It's a perfectly valid configuration. (Although, if you're really running it like a service, you'd be better off with SQL Server Express Edition instead).
First, you need to make sure that the localdb instance is fired up. That can be your application, or it can be via the SqlLocalDB Utility. See here: https://docs.microsoft.com/en-us/sql/tools/sqllocaldb-utility?view=sql-server-2017
Second, you need to make sure that TCP is enabled. Details of setting up a shared instance are described here: https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-express-localdb?view=sql-server-2017
Hope that helps.
User contributions licensed under CC BY-SA 3.0