1
votes

I wrote my C# code in Visual Studio with a service-based sql database and it worked on my windows 10 correctly. After that, I copied the "released" folder of the project to another computer with windows server. But when I run the application on new computer a get 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: 26 - Error Locating Server/Instance Specified)

It seems the reason is that a sql server instance is not installed on new windows.

my connection string to that database in my code is:

@"Data Source=.\sqlexpress;AttachDbFilename=" + Directory.GetCurrentDirectory() + @"\MembersDB.mdf;Integrated Security=True;User Instance=True"

My question is what exactly should I install on new computer to solve the problem and where can I download it?

1

1 Answers

1
votes

You answered your question yourself : "It seems the reason is that a sql server instance is not installed on new windows.". Just go to the Microsoft website and grab a copy of SQL Server express (it's free). Remember to copy your database logic to the new SQL Server instance.

EDIT: To copy your database logic:

  • Open SQL Server Management Studio on your development machine
  • Right click on the database you need to copy
  • Select Tasks > Generate Scripts
  • Next > Entire Database > Next > Done
  • Open and execute the generated script on your target machine