Reputation:
I'm kinda new with C# and I'm having this problem.
I'm trying to connect to my database in SQL Server 2008 R2 from VIsual Studio 2015 Community.
My server name is ERIC-LAPTOP\SQLMANAGER, but the "\" occurs an error:
string connetionString = null;
string servername = "ERIC-LAPTOP\SQLMANAGER";
string database = "RPG_Ressourses";
SqlConnection connection;
connetionString = "Data Source=" + servername + ";Initial Catalog=" + database + ";Integrated Security=SSPI;";
connection = new SqlConnection(connetionString);
Is there a way to make it accept \ as a normal character or is there a way to make it work without changing the name of the server instance?
I put the servername and database into var because it will be part of the parameters eventually.
Upvotes: 1
Views: 41
Reputation: 63065
use @
string servername = @"ERIC-LAPTOP\SQLMANAGER";
or \\
string servername = "ERIC-LAPTOP\\SQLMANAGER";
Upvotes: 1