C # .Net SqlConnection to LocalDB

I feel stupid, even if I need it, but I have to miss something.

I am just trying to open a new SqlConnection for my LocalDB instance on my development machine. Visual Studio 2013.

I can connect to LocalDB from SSMS and have no problems. In the solution I'm working on, I can and successfully connected to LocalDB with Entity Framework.

In another project, as part of the same solution, I am trying to connect to LocalDB with an old school SqlConnectionobject, and this is where I just completely fail.

Here is the connection string I'm trying to use,

SqlConnection SqlConn = new SqlConnection("Server=(LocalDb)\v11.0;Initial Catalog=DBNAME;Integrated Security=SSPI;Trusted_Connection=yes;");

When I call SqlConn.Open(), I get an error message stating that it cannot find or connect to the database.

This does not really matter, since the connection string will be changed when it is combined with production, but I cannot understand for life why I cannot get this object SqlConnectionto talk to LocalDB

+4
source share
1 answer

It looks like you might need to avoid the slash in your connection string.

Turn this: "Server=(LocalDb)\v11.0;Initial Catalog=DBNAME;Integrated Security=SSPI;Trusted_Connection=yes;"

In it: "Server=(LocalDb)\\v11.0;Initial Catalog=DBNAME;Integrated Security=SSPI;Trusted_Connection=yes;"

+6
source

All Articles