error with constring in c# while connecting database
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
The problem is the database property showing connection string data source as "xyz\sqlexpress" ..if i put the same connection string it wil show the error as "escape sequence used"(\)...if i modify connection string as only "xyz" then it wil give above given error...so please suggest me some s开发者_Python百科olution for this...
"i have allowed remote connection" and what is exactly this instance name?
You need to escape the backslash character:
If you construct the connection string in code:
"DataSource=xyz\\sqlexpress"
In your configuration file:
"DataSource=xyz\sqlexpress"
If your connection string contains a backslash ("\"), you need to double it up ("xyz\\sqlexpress") or escape it with @ (@"xyz\sqlexpress").
精彩评论