So I am trying to connect a local file database when I debug the program or use it anywhere on my dev machine, it works absolutely fine. Whenever I try to take the files and run it on a different machine I get
Error 50 cannot connect to the localdb: local database runtime error occurred, The specified LocalDB instance does not exist
Now my issue is, I kind of know what is causing the issue, I just dont know how to resolve it.
I have installed SQL Server express 2016 on my testing machine (the one it doesnt work on) and the localDb never gets initialized.
On my Dev machine, I can goto "C:\Program Files\Microsoft SQL Server\130\LocalDB"
However on my test machine I only have "C:\Program Files\Microsoft SQL Server\130\" No LocalDB.
I believe my issue is that I am never actually creating the sql server instance rather just calling the file (see code below) but I dont know how to initalize a local instance of an sql server. I have searched and tried different methods but nothing is working for me.
public SqlConnection connectionOpen()
{
string databaseDirectory = Convert.ToString(Directory.GetCurrentDirectory() + @"\gameDatabase.mdf");
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source =(LocalDB)\MSSQLLocalDB; AttachDbFilename ="+databaseDirectory +"; Integrated Security = True";
conn.Open();
return conn;
}
public void connectionClose()
{
string databaseDirectory = Convert.ToString(Directory.GetCurrentDirectory() + @"\gameDatabase.mdf");
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source =(LocalDB)\MSSQLLocalDB; AttachDbFilename ="+databaseDirectory + "; Integrated Security = True";
conn.Close();
}
As mentioned this works flawlessly on my local dev machine, no matter where the exe and mdf files are (as long as they're in the same directory as thats how im finding the mdf file in code), but as soon as I try to run it on a different machine I get a connection error.
Any help would be really appreciated! I am pulling my hair out!