ConnectionString中的错误不支持关键字:'提供商'

时间:2017-02-15 03:21:13

标签: c# mysql connection connection-string

我正在使用EntityConnectionStringBuilder为MySQL数据库创建ConnectionString但我收到错误"不支持关键字:'提供商'"我不知道为什么会收到此错误

我的代码

EntityConnectionStringBuilder csb = new EntityConnectionStringBuilder();
            csb.ProviderConnectionString = "Server=Ip;User Id=user;Password=123456;database=dev pooling=false";
            csb.Provider = "MySql.Data.MySqlClient";
            return csb.ConnectionString; 

请帮我解决这个错误,并使用Entity Framwork

1 个答案:

答案 0 :(得分:1)

你错过了一个分号“;”在你的连接字符串中。我不知道修复是否能解决这个问题。提供程序被归咎于您的错误消息,因为它是EntityConnectionStringBuilder中连接字符串之后的下一个属性:

EntityConnectionStringBuilder csb = new EntityConnectionStringBuilder();
            csb.ProviderConnectionString = "Server=Ip;User Id=user;Password=123456;database=dev;pooling=false";
            csb.Provider = "MySql.Data.MySqlClient";
            return csb.ConnectionString; 

我建议使用单独的SQLConnectionStringBuilder,并将Pooling属性设置为:{/ p>

string connectionString = "Server=Ip;User Id=user;Password=123456;database=dev";
System.Data.SqlClient.SqlConnectionStringBuilder scsb = new System.Data.SqlClient.SqlConnectionStringBuilder(connectionString);
scsb.Pooling = true;

EntityConnectionStringBuilder csb = new EntityConnectionStringBuilder();
csb.ProviderConnectionString = scsb.ConnectionString; 
csb.Provider = "MySql.Data.MySqlClient";
return csb.ConnectionString;