我在连接字符串中的’字符时遇到麻烦。实体框架引发异常:
I'm having a trouble with the ' character in a connection string. Entity Framework throws an exception saying:
初始化字符串的格式不符合从索引开始的规范
Format of the initialization string does not conform to specification starting at index
我尝试了建议的答案此处和
I tried the answers suggested here and here to no avail.
我也尝试使用 SqlConnectionStringBuilder 类构造它,并得到相同的异常结果。
I also tried constructing it with SqlConnectionStringBuilder class and got the same exception as a result.
有人可以帮我吗?
预先感谢。
编辑:
连接字符串确实位于web.config文件中,它看起来像这样:
The connectionstring is indeed in the web.config file and it looks like this:
<add name="TestEntities" connectionString="metadata=res://*/DAL.TestModel.csdl|res://*/DAL.TestModel.ssdl|res://*/DAL.TestModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\testsource;initial catalog=testdb;User Id=testuser;Password=test'password;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />问题在于 Password = test'password 位。
Password ='test&'password'不起作用。
推荐答案我终于迷失了一个正确答案。看起来,您必须用单引号将值引起来,并另外复制内撇号以使其逃逸,如下所示:
I have finally stumbled upon a correct answer. It appears, you have to surround the value with single quotes and additionally duplicate the inner apostrophe in order to escape it, like this:
Password = 'test'password'
这是一个愚蠢的问题,浪费了很多时间。我希望它可以节省将来的时间。
This is such a dumb problem to waste this much time on. I hope it saves somebody time in the future.
感谢大家的参与。
更多推荐
连接字符串中的撇号(单引号)
发布评论