关于c#连接数据库
我租用了一个虚拟主机,之前连接数据库还好,但是今天连接时就有问题了,说unable to find the requested .net framework data provider,我连接数据库的代码是这样的:
public class ConnDB
{
private static string connString;
private DbConnection conn;
public ConnDB()
{
connString = "Data Source=localhost;Initial Catalog=hanjieson;User ID=hanjieson;Password=wo114025;";
conn = null;
}
~ConnDB()
{
this.CloseConnect();
}
public bool StartConnect()
{
String providerInvariantName = "MySql.Data.MySqlClient";//数据库provider不变名
DbProviderFactory f = DbProviderFactories.GetFactory(providerInvariantName);
if (conn != null)
conn.Dispose();
conn = f.CreateConnection();
conn.ConnectionString = connString;
try
{
if (conn.State == ConnectionState.Closed)
conn.Open();
return true;
}
catch (Exception)
{
return false;
}
}
}
请求大家帮帮我,我很急,今天晚上要交一个作品!!!!先谢谢大家了!
[解决办法]
解决方案->
[解决办法]
未能加载程序集 MySql.Data
------解决方案--------------------
the solution would be to have mysql.dll in your bin folder, it happens that what ever server your solution deployed doesn't have the related my sql data provider installed to GAC