Published windows app not connecting to LocalDB

0

I have a windows application in C#, works fine on my laptop even when published but as soon as I send it to another machine, it gives this error "System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist.)"

What I have done: I used publish tab in the app properties page, doesn't work. I used Project Setup project for the app, I even included SQL Server 2012 Express LocalDB as prerequisites and I confirmed that it installed it on client machine, but it just won't work. I also saved my db file .mdf in AppData folder, here is my connection string.

// init connection
string fileName = "TeamDB.mdf";
string targetPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\TeamCBT";

// create directory is it doesn't exist yet
if (!Directory.Exists(targetPath))
    Directory.CreateDirectory(targetPath);


string target = Path.Combine(targetPath, fileName);
if (!File.Exists(target))
{
     string source = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), fileName);
      File.Copy(source, target);
}

connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=" + targetPath + "\\TeamDB.mdf;Integrated Security=True;Timeout=30";

I have really run out of solutions, I have searched and searched, please help me. Thanks

c#
sql-server
windows
windows-installer
localdb
asked on Stack Overflow Mar 31, 2020 by David • edited Mar 31, 2020 by jarlh

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0