0

I am using a SQL local database attached in the project when I copy the whole project on another pc and run bin\Debug myapp.exe its run but give me an error connecting to the database 1

but when I install visual studio on the pc and run the project from vs its works fine. and when I delete its go back to the same error I want to make it run without the visual studio, please that is my connection string

string domain = (AppDomain.CurrentDomain.BaseDirectory).ToString();                                      
sqlcon = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename="+ domain + "selapp.mdf;" + "Integrated Security=True");

I hope you can help me, please

kiner_shah
  • 3,939
  • 7
  • 23
  • 37
  • Side point: [what's the issue with AttachDbFilename](https://stackoverflow.com/questions/11178720/whats-the-issue-with-attachdbfilename) – Charlieface Oct 30 '21 at 19:16

1 Answers1

0

You will need to have LocalDB (SQL Server Express) installed on that computer that you copied the project (including the executable). This typically gets installed through the Visual Studio Installer (depending on the workload or components you select for installation). If you are planning on deploying your application to other computers you should look into setting up an installer project. This is where you would want to include the SqlLocalDB.msi (dependency) so that it gets installed with your application.

Glenn Kees
  • 106
  • 4