不支持关键字:'datasource'

时间:2017-05-01 23:03:37

标签: asp.net-mvc visual-studio-2012

我正在尝试使用姓名为connectionString的最后sqlConString

这是我的连接字符串:

<connectionStrings>
    <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-saroh-20170305155508;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-saroh-20170305155508.mdf" />
    <add name="crowdfundingEntities4" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\crowdfunding.mdf;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    <add name="userdataEntities6" connectionString="metadata=res://*/Models.MyModel.csdl|res://*/Models.MyModel.ssdl|res://*/Models.MyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\userdata.mdf;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    <add name="sqlConString" connectionString="DataSource=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\crowdfunding.mdf;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;"/>
  </connectionStrings>

1 个答案:

答案 0 :(得分:0)

我认为您的问题是连接字符串Data Source在字词之间有空格但您的设置为DataSource

所以试试

<add name="sqlConString" connectionString="Data Source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\crowdfunding.mdf;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;"/>

如果这不能解决您的问题,请尝试:

  1. 提供providerName
    如果您使用普通的ado .net,那么它应该是providerName="System.Data.SqlClient"
    如果使用实体框架需要添加providerName="System.Data.EntityClient"并在连接字符串中添加metadata部分(请参阅您的userdataEntities6

  2. 如果您使用的是实体框架,则添加providerName和修改connectionString以包含metadata的部分也可以尝试将&quot;更改为' 有关这方面的更多信息,请查看https://blogs.msdn.microsoft.com/rickandy/2008/12/09/explicit-connection-string-for-ef/