首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

关于c#连接数据库,该怎么解决

2013-04-21 
关于c#连接数据库我租用了一个虚拟主机,之前连接数据库还好,但是今天连接时就有问题了,说unable to find t

关于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 
------解决方案--------------------


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

热点排行