asp.net - 通过 CreateUserWizard 连接 SQL 数据库时出错
问题描述
我在 Web 表单中添加了“创建用户向导”并更改了 web.config 文件以更改数据库地址。我运行了这个表单并填写了字段,然后单击了提交按钮。出现此错误页面:“'/' 应用程序中的服务器错误。初始化字符串的格式不符合从索引 0 开始的规范。”。之后我检查了我输入的连接字符串,没关系。我在另一个应用程序上检查了它。这是 web.config 文件:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add
name="MyConnectionString"
connectionString="Data Source=DESKTOP-RMNK148;Initial Catalog=MySiteDatabase;User ID=MyUserID;Password=MyPassword"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
<system.web>
<membership defaultProvider="MyProvider">
<providers >
<clear/>
<add
name="MyProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionString="MyConnectionString"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="false"
passwordFormat="Hashed"
applicationName="/"
/>
</providers>
</membership>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
</configuration>
解决方案
似乎您的UserID
参数在提供的连接字符串中无效。尝试User ID
(使用空格)代替:
<add name="MyConnectionString"
connectionString="Data Source=DESKTOP-RMNK148;Initial Catalog=MySiteDatabase;User ID=MyUserID;Password=MyPassword"
providerName="System.Data.SqlClient"/>
请注意,如果连接字符串的格式不正确或包含无效字符(如使用分号的数据库密码),则始终会出现“初始化字符串的格式不符合从索引 0 开始的规范”错误。
推荐阅读
- asp.net-mvc - 托管一个 ASP.net MVC 网站并从外部访问它
- maven - Maven Cobertura 忽略命令行中的琐碎
- php - PHP - ftp_put(): 文件不存在 - 但它存在吗?
- reporting-services - 根据值向下钻取 SSRS 报告中的列
- reactjs - Hyperledger Composer 的前端?
- javascript - debounce and react window resize this reference issue
- ios - 如何使用自动布局在 UIScrollView 中为视图高度设置动画?
- java - API 26 中的服务
- c# - .NET Core 中的 AppDomainAppId?
- javascript - 如何使用 React Native 调用没有本机模块的本机代码