【问题标题】:Format of the initialization string does not conform to specification starting at index 227初始化字符串的格式不符合从索引 227 开始的规范
【发布时间】:2017-02-13 00:36:17
【问题描述】:
  <connectionStrings>
    <add name="CentralDb" connectionString=
     "metadata=.\CentralDb.csdl|.\CentralDb.ssdl|.\CentralDb.msl;
      provider=System.Data.SqlClient;
      provider connection string=CentralDb&quot;Data Source=U19675709\SQLEXPRESS&quot;Initial Catalog=CentralDb&quot;Integrated Security=True;MultipleActiveResultSets=False&quot;" 
      providerName="System.Data.EntityClient" /> 
          <add name="DefaultConnection" connectionString=
     "metadata=.\CentralDb.csdl|.\CentralDb.ssdl|.\CentralDb.msl;
      provider=System.Data.SqlClient;
      provider connection string=CentralDb&quot;Data Source=U19675709\SQLEXPRESS&quot;Initial Catalog=CentralDb&quot;Integrated Security=True;MultipleActiveResultSets=False&quot;" 
      providerName="System.Data.EntityClient" /> 

  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

我正在尝试为使用数据库的 EntityFramework 创建连接字符串。

初始化字符串的格式不符合从索引 227 开始的规范。

...是我在尝试使用上面的 web.config

运行时收到的错误

【问题讨论】:

    标签: c# sql .net entity-framework connection-string


    【解决方案1】:

    您的连接字符串在其DataSource 描述中似乎有额外的引号(&amp;quot),而且,就在它之前,它似乎在provider connection string 的开头有一个额外的CentralDb

    试试这个:

    <add name="CentralDb" connectionString=
     "metadata=.\CentralDb.csdl|.\CentralDb.ssdl|.\CentralDb.msl;
      provider=System.Data.SqlClient;
      provider connection string=&quot;Data Source=U19675709\SQLEXPRESS;Initial Catalog=CentralDb;Integrated Security=True;MultipleActiveResultSets=False&quot;" 
      providerName="System.Data.EntityClient" /> 
    

    【讨论】:

      猜你喜欢
      • 2012-01-04
      • 2015-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多