6

我正在使用實體框架代碼第一個4.3 + Azure並且難以連接到數據庫。我得到的錯誤是以下(第一查詢):實體框架代碼第一個Azure連接

Keyword not supported: 'server'. 

,我有以下連接在我的web.config成立

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

    <connectionStrings> 
    <add name="TestDBContext" 
     connectionString="Server=tcp:[SUBSCR].database.windows.net,1433;Database=[MyDB];User ID=[user];Password=[pass];Trusted_Connection=False;Encrypt=True;PersistSecurityInfo=True" 
     providerName="System.Data.EntityClient" /> 
    </connectionStrings> 

我的DbContext實現類使用連接字符串的名字:

public class MyContext : DbContext, IMyContext 
    { 
     public MyContext() 
      : base("TestDBContext") 
     { 
      Configuration.LazyLoadingEnabled = true; 
      Configuration.ProxyCreationEnabled = true; 
     } 

你能告訴發生了什麼事嗎?

回答

0

我試過這樣,它可能會幫助你。可能是1433正在問題,它是否沒有端口?或者是什麼? 。像這樣嘗試。

檢查此鏈接Windows Azure with Sql

<add name="dbContext" connectionString="Server=tcp:xxxxxxxx.database.windows.net;Database=xxxxxxxx;User [email protected];Password=xxxxxxxxxx;Trusted_Connection=False;Encrypt=True;" providerName="System.Data.EntityClient" /> 
+0

嘗試過它,它不起作用... 1433是SQL Server的默認端口,我複製粘貼來自Azure訂閱/數據庫的連接字符串。 – 2012-02-11 13:44:12

0

嘗試這種情況:

數據源= TCP:YOUR-DATABASE-HERE.database.windows.net,1433; Database = GolfRounds; 用戶ID =您的用戶名@您的服務器;密碼= YOUR-密碼; Trusted_Connection = FALSE;加密= TRUE;

還有一個MSDN文章http://msdn.microsoft.com/en-us/library/windowsazure/ff951633.aspx,這可能會有所幫助。

+0

不支持的關鍵字:'數據源'。 – 2012-02-12 17:35:32

5

我剛剛有同樣的問題。

您錯過了實體框架需要的連接字符串中的所有元數據。由SQL Azure提供的連接字符串需要插入EF連接字符串的provider connection string參數中。

<add name="MyConnectionString" connectionString="metadata=res://*/Model.Model.csdl|res://*/Model.Model.ssdl|res://*/Model.Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;[PUT SQL AZURE CONN STRING HERE]&quot;" providerName="System.Data.EntityClient" />

你需要使用元數據從您自己的項目。我從一個從現有數據庫生成的EF項目中提取元數據。

+1

我首先使用EF代碼+ DbContext(我沒有從數據庫生成我的數據模型),所以我沒有在開發時提供任何元數據。 – 2012-07-26 12:26:02

+7

@Sese如果您使用Code First,那麼您的連接字符串提供程序應該是'System.Data.SqlClient'而不是'System.Data.EntityClient'。 – ryanmcdonnell 2012-07-26 23:11:11

2

我有同樣的問題。我解決了,把在web.config此的ConnectionString:

<add name="eManagerTurModelConnection" connectionString="metadata=res://*/ORM.eManagerFinanceModel.csdl|res://*/ORM.eManagerFinanceModel.ssdl|res://*/ORM.eManagerFinanceModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=<server>.database.windows.net;Initial Catalog=eManagerTur;Integrated Security=False;User ID=<user>;Password=<Password>;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 

後,我打消了我的網站的ConnectionString,工作,因爲它沒有得到,我在我的web.config中添加的連接字符串。

英語不好...... =)

2

供應商應的providerName =「System.Data.SqlClient的」

我從連接到VS蔚藍,然後看了看屬性並設置我的連接字符串和提供者名稱。

<add name="context" connectionString="Data Source=myServer,myPort;Initial Catalog=myDBName;Persist Security Info=True;User ID=myUserName;Password=myPassword;" providerName="System.Data.SqlClient"/> 

我當時能夠在沒有問題的情況下運行update-database。

-1

我有一個類似的問題,我沒有訪問元數據,在這種情況下,你需要使用System.Data.SqlClient作爲提供者。您還需要將MultipleActiveResultSets = True添加到連接字符串

相關問題