英文:
Why can't I modify and do anything with my DB tables through vs2019
问题
当我在vs2019中将本地数据库与我的项目连接时,它会显示连接成功,一切正常。但当我右键单击表格并尝试执行任何操作时,它会弹出一个错误消息,内容为“无法检索服务器版本”。
另一个引起问题的地方是我的连接字符串是:
public static SqlConnection connection = new SqlConnection("Data Source=DESKTOP-0R58GC3\\SQLEXPRESS;Initial Catalog=SchoolDB;Integrated Security=True");
它报告这一部分出错:
Source=DESKTOP-0R58GC3\SQLEXPRESS
更具体地说,反斜杠“\”未被识别,这是在尝试构建时给出的错误信息:
错误 CS1009 无法识别的转义序列 School Database C:\Users\merti\OneDrive\Работен плот\School Project\School Database\School Database\DB.cs 14 N/A
已尝试重新连接和连接多次,也尝试检查所有服务是否正在运行(除了SQL代理外,我不知道为什么无法启动它)。
英文:
When I connect my local DB with my project in vs2019 it says that my connection was successful, all good. But when I right click on a table and try to do whatever it pops up an error message with "Failed to retrieve server version".
Another thing that makes a problem is my connection in is:
public static SqlConnection connection = new SqlConnection("Data Source=DESKTOP-0R58GC3**\**SQLEXPRESS;Initial Catalog=SchoolDB;Integrated Security=True");
it says that this part:
> Source=DESKTOP-0R58GC3\SQLEXPRESS
More particularly the \ is unrecognized, this is the error that it gives me after trying to build it:
> Severity Code Description Project File Line Suppression State
> Error CS1009 Unrecognized escape sequence School
> Database C:\Users\merti\OneDrive\Работен плот\School Project\School
> Database\School Database\DB.cs 14 N/A
Tried reconnecting and connecting a hundred times, tried to see of all my services are running (they are expect for SQL Agent I don't why but I can not start it).
答案1
得分: 1
反斜杠 \ 是用来处理特殊字符的转义字符。
因此,如果您需要将其视为普通字符来使用,您需要对其进行转义:
public static SqlConnection connection = new SqlConnection("Data Source=DESKTOP-0R58GC3\\SQLEXPRESS;Initial Catalog=SchoolDB;Integrated Security=True");
请注意它是如何被复制的。这是因为我正在使用它来指示我正在转义下一个字符,即它本身。
您可以在这里了解更多信息。
英文:
The backslash \ is a escaping character used to deal with special characters.
For this reason, if you need to consume it as a regular character, you need to escape it:
public static SqlConnection connection = new SqlConnection("Data Source=DESKTOP-0R58GC3\\SQLEXPRESS;Initial Catalog=SchoolDB;Integrated Security=True");
Notice how it's duplicated. This is because I am using it to indicate that I am escaping the next character, which is itself.
You can read more about it here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论