C#Entity Framework建立mysql數據庫中報錯: System.ArgumentException:「不支持關鍵字: 「port」

  最近寫winform程序時候,因爲並不常常寫.net程序,遇到一個問題,我開發的語言用的是C#,開發工具VS,可是用EF框架建立mysql數據庫的時候,遇到一個問題,鏈接字符串的時候,報錯
mysql

 

System.ArgumentException:「不支持關鍵字: 「port」。」sql

 

找到了有三種解決方案,我採起的是第三種,親測可用:數據庫

 

第一:更改defaultConnectionFactory配置:框架

<defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6"></defaultConnectionFactory>

  

第二種:使用命名配置鏈接字符串並明確指定提供者:
<connectionStrings>
    <add name="XXDB" providerName="MySql.Data.MySqlClient" connectionString="server=myservername;port=3306;uid=myaccount;database=mydb;pwd=mypwd123" />
</connectionStrings>
 

   而且更改構造函數ide

public XXDB()
{
    // ...
}

  

第三種:
使用DbConfigurationTypeAttribute :

DbConfigurationTypeAttribute
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class XXDB : DbContext
{
    // ...
}
相關文章
相關標籤/搜索