初始化字符串的格式不符合从索引 0 开始的规范
我有一个 ASP.Net MVC 应用程序,它在我的本地开发计算机上运行良好。但部署到IIS7后尝试登录时出现以下错误:
初始化字符串格式不符合规范 从索引 0 开始
大多数发布此错误的人通过以某种方式更改连接字符串来解决该错误。但是,我在本地和部署的应用程序上的连接字符串是相同的。连接字符串是这样的:
<add name="ApplicationServices" connectionString="Data Source=*server*\*instance*;Initial Catalog=*database*;Integrated Security=True;"
providerName="System.Data.SqlClient" />
在我的例子中是什么导致了这个错误?
I have an ASP.Net MVC application which runs fine on my local development machine. But when deployed to IIS7 gives the following error when trying to log in:
Format of the initialization string does not conform to specification
starting at index 0
Most people who post this error resolve it by changing their connection string in some way. However my connection string on the local and deployed application are the same. The connection string is like this:
<add name="ApplicationServices" connectionString="Data Source=*server*\*instance*;Initial Catalog=*database*;Integrated Security=True;"
providerName="System.Data.SqlClient" />
What is causing this error in my case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
Web.config:
在 aspx.cs 页面中,代码必须按以下格式编写:
Web.config :
In aspx.cs Page the code must be written in the below format :
当我选中启用 CodeFirst 迁移复选框时,Web 部署工具在配置中创建了错误的行。
Web Deployment tool created wrong line in config when I checked Enable CodeFirst Migrations check-box.
就我而言,我不小心在 conn 字符串中写了“password:”而不是“password=”
In my case I accidentally wrote "password:" instead of "password=" in my conn string
检查以确保 Web.config 中连接字符串的凭据正确。我的缺少具有数据库权限的帐户的密码。
Check to make sure the credentials are correct for the connection string in Web.config. Mine was missing the password for the account with permissions to the database.
我遇到了同样的错误。就我而言,这是配置转换无法正常工作。
当涉及到连接字符串时,配置转换存在问题。
一些参考:
另外,您还可以在 aspx.cs 页面中编写代码,
对于那些想了解有关 简洁。
希望这有帮助。
I encountered the same error. In my case it was the config transform not working properly.
There is an issue with config transforms when it comes to connection strings.
Some reference:
Also one can write the code in the aspx.cs page as
For those who would like to find out more about Dapper.
Hope this helps.
如果您一直使用 Visual Studio 发布向导进行部署,并在“设置”中选中了执行代码优先迁移复选框,则新的 ConnectionString 会自动添加到 Server Web.config 文件中,类似于第二个下面一行:
首先,注意添加的连接字符串包含“ConnetionString”:我认为它应该是“ConnectionString”!但这不是解决方案。
要避免出现“初始化字符串的格式不符合从索引 0 开始的规范”错误,请在发布向导中执行以下操作:
“远程连接字符串”字段
执行上述操作时,将连接字符串添加到服务器Web.config读取:
并且不再出现“初始化字符串的格式不符合从索引0开始的规范”错误。
If you have been using the Visual Studio Publish Wizard for deployment and checked the Execute Code First Migrations check box in Settings, a new ConnectionString is automatically added to the Server Web.config file, similar t to the 2nd line below:
First, notice the added connection string contains "ConnetionString": I think it should be "ConnectionString"! But that's not the solution.
To avoid the "Format of the initialization string does not conform to specification starting at index 0" error, do the following in the Publish Wizard:
"Remote Connection String" field
When doing the above, the connection string added to the Server Web.config reads:
and the "Format of the initialization string does not conform to specification starting at index 0" error no longer occurs.
当我在包管理器控制台中使用命令:“更新数据库”时,我遇到了同样的问题。
要修复,请确保将启动项目设置为您要更新的项目。
例如,我有Db项目和Web项目,请确保在Db项目上设置启动项目,当运行“Update-Database”时,否则,它将尝试在Web项目内搜索。
I has the same issue, when I use command: "Update-Database" in Package Manager Console.
To Fix, make sure set startup project to the project which you want to do update.
E.g. I got Db project and Web project, make sure set startup project on Db project, when run "Update-Database", otherwise, it will try to search inside Web project.
SQL Server 上的权限设置不正确。我现在已经通过正确设置服务器权限解决了这个问题。
The permissions on the SQL server were not correctly set up. I have now resolved this by properly setting up the server permissions.