1

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?

Persian LionKing
  • 304
  • 1
  • 5
  • 19

1 Answers1

1

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
Romano Zumbé
  • 7,893
  • 4
  • 33
  • 55
  • How can I copy my database logic to new sql server instance? – Persian LionKing Jun 21 '17 at 08:02
  • hi. I copied the memberDB.mdf to the same folder as application executive folder and I got the same error. After that, I changed my conString as you said and copied the mdf file to the given location and I got the same error again. – Persian LionKing Jun 23 '17 at 03:39
  • Finally I installed sql server express on that new computer and application ran correctly. But I think There should be a solution to run this applications with mdf database to run without installing sql server – Persian LionKing Jun 23 '17 at 05:14
  • 1
    I've checked that and turns out, there isn't. If my answer solved your problem, please mark it as correct. https://stackoverflow.com/questions/10366586/is-it-possible-to-access-a-mdf-database-without-sql-server – Romano Zumbé Jun 23 '17 at 05:30