关于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;
}
}
}
请求大家帮帮我,我很急,今天晚上要交一个作品!!!!先谢谢大家了!
------解决方案-------------------- 解决方案->
------解决方案-------------------- 引用: 引用:解决方案->
还是没解决,报错说:Could not load file or assembly 'MySql.Data, Version=5.1.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. 系统找不到指定的……
未能加载程序集 MySql.Data
------解决方案-----------