Asp.net

不支持關鍵字:“元數據”。?使用 MVC3 的 Entityt 框架中的 Sql 連接

  • October 18, 2012

我將 Entity Framework 4 與我的 Asp.Net MVC3 應用程序一起使用。我的問題是我正在使用實體框架對我的數據庫執行操作,這工作正常。出於其他目的,我還使用 Sql Connection 來儲存和檢索數據庫中的數據。我正進入(狀態

[Keyword not supported: 'metadata']

連接我的數據庫時出錯。

這是我的網路配置

 <add name="VibrantEntities" connectionString="metadata=res://*/Vibrant.csdl|res://*/Vibrant.ssdl|res://*/Vibrant.msl;provider=System.Data.SqlClient;provider connection string="data source=KAPS-PC\KAPSSERVER;initial catalog=vibrant;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />

我正在使用類庫,所以這是我的應用程序配置。

  <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

  <add name="VibrantEntities" connectionString="metadata=res://*/Vibrant.csdl|res://*/Vibrant.ssdl|res://*/Vibrant.msl;provider=System.Data.SqlClient;provider connection string="data source=KAPS-PC\KAPSSERVER;initial catalog=vibrant;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />

ADO.NET(在本例中SqlConnection)的連接字元串不採用這種格式。您正在使用特定於實體框架的一個。ADO.NET 應該是這樣的:

"data source=KAPS-PC\KAPSSERVER;initial catalog=vibrant;integrated security=True"

因此,總而言之,您需要兩個單獨的連接字元串,一個用於 EF,一個用於 ADO.NET

引用自:https://stackoverflow.com/questions/12946099