简体   繁体   English

连接字符串VS asp.net

[英]Connectionstring VS asp.net

I have a problem with connection with DB by connectionstring. 我有一个通过connectionstring与DB连接的问题。 Here is my code: 这是我的代码:

SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf; Integrated Security=True;User Instance=False";

And visual Studio is telling that the error is in parameter AttachDbFilename - accurately with this slash after "|Data Directory|". 而且visual Studio告诉您错误出在参数AttachDbFilename中-准确地在“ | Data Directory |”之后带有此斜杠。 I tried using 2 slashes - no results. 我尝试使用2个斜杠-没有结果。 I am using VS 2013. The path to database is ok. 我正在使用VS2013。数据库的路径正常。 I don't know where the problem is. 我不知道问题出在哪里。 I made a connection by component ant there the connectionstring was exactly like my connection ant this solution was working. 我通过组件ant建立了连接,那里的连接字符串与我的连接ant完全一样。

这是转义连接字符串的问题,每次要使用\\时只需使用\\\\即可:

"Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\Database.mdf; Integrated Security=True;User Instance=False"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM