【问题标题】:Error in connect to SQL database through CreateUserWizard通过 CreateUserWizard 连接 SQL 数据库时出错
【发布时间】:2018-08-10 09:00:32
【问题描述】:

我在 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=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>
</configuration>

【问题讨论】:

    标签: asp.net createuserwizard


    【解决方案1】:

    似乎您的UserID 参数在提供的连接字符串中无效。改用User ID(带空格):

    <add name="MyConnectionString"
         connectionString="Data Source=DESKTOP-RMNK148;Initial Catalog=MySiteDatabase;User ID=MyUserID;Password=MyPassword"
         providerName="System.Data.SqlClient"/>
    

    请注意,“初始化字符串的格式不符合从索引 0 开始的规范” 如果连接字符串格式不正确或包含无效字符(如数据库密码使用分号)。

    参考:SQL Server Connection Strings

    相关问题:Format of the initialization string does not conform to specification starting at index 0

    【讨论】:

    • 谢谢哲也,我试过了,但错误仍然存​​在。
    • 正如我所说,我在其他应用程序上测试了这个 cs,并且连接成功。
    • 你能提供错误堆栈跟踪吗?有时它不仅是由错误的 web.config 连接字符串引起的,而是使用了另一种需要连接字符串但您提供连接字符串密钥的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-09
    • 2013-01-26
    • 1970-01-01
    • 2013-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多