0

I'm working on C# .net application that needs to connect to a simple database. This database is btw in the same visual studio project and is called Playerdatabase.mdf.

In the application I want to connect to the database by using the following code:

string connectionString = "Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\\Users\\User1\\Documents\\Visual Studio 2013\\Projects\\ProreactorTest\\ProreactorTest\\Playerdatabase.mdf;Integrated Security=True;Connect Timeout=30";

SqlConnection con = new SqlConnection(connectionString);

con.Open();

But when I try to run the application and when it calls the open() method I got the exception:

Additional information: 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

Inner exception: can not find network path.

I looked at the path (by browsing to it) and it looks fine. I also read that disabling the firewall works, tried that but got the same exception.

Does anybody have a idea or suggestion? Any feedback is welcome!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Roy08
  • 253
  • 2
  • 7
  • 21
  • Did you get the connection string from the properties of the database? –  Mar 17 '15 at 21:22
  • this exception usually occures when the connection string is not correct or the `SQL-SERVER` services are stopped .. There are also lots of things by which this excepiton occured http://stackoverflow.com/questions/18060667/cannot-connect-to-server-a-network-related-or-instance-specific-error – Khurram Ali Mar 17 '15 at 21:27
  • Why `Data Source=(LocalDB)` but not `Data Source=.` or `Data Source=localhost`? – i486 Mar 17 '15 at 21:31
  • Instead of `Data Source=(LocalDB)\v11.0`, does `Server=(LocalDB)\v11.0` work instead? – Brendan Green Mar 17 '15 at 23:49

0 Answers0