Exemple #1
0
        //改变连接
        void ChangeConnection(string csName)
        {
            DbConnDAL dal = new DbConnDAL();

            var model = dal.FindOne(csName);

            currentSchema = DbSchemaFactory.Create(model.Name);

            List <SODatabase> dbList = currentSchema.GetDatabaseList();

            cbDatabase.Items.Clear();
            foreach (SODatabase db in dbList)
            {
                if (db.IsSystemDatabase)
                {
                    continue;
                }
                cbDatabase.Items.Add(db);
            }

            //if (cbDatabase.Items.Count > 0)
            //{
            //    DbName = cbDatabase.Items[0].ToString();
            //    cbDatabase.SelectedIndex = 0;
            //}
            //else
            //{
            //    DbName = string.Empty;
            //}

            foreach (object item in cbConnectionStrings.Items)
            {
                if (item.ToString() == CSName)
                {
                    cbConnectionStrings.SelectedItem = item;
                    break;
                }
            }
        }
        private void cbConnectionStrings_SelectedIndexChanged(object sender, EventArgs e)
        {
            tvDatabase.Nodes.Clear();
            var dal   = new DbConnDAL();
            var model = dal.FindOne(cbConnectionStrings.SelectedItem.ToString());

            dbSchema = DbSchemaFactory.Create(model.Name);
            DbSchemaHelper.Instance.CurrentSchema = dbSchema;

            TreeNode root = new TreeNode(model.Name, 0, 0);

            root.ToolTipText = model.ConnectionString;
            tvDatabase.Nodes.Add(root);

            Main m = this.ParentForm as Main;

            m.ClearDbList();

            this.Cursor = Cursors.WaitCursor;
            IList <SODatabase> dbList = dbSchema.GetDatabaseList();

            this.Cursor = Cursors.Default;

            foreach (SODatabase db in dbList)
            {
                TreeNode dbNode = new TreeNode(db.Name, 1, 1);
                dbNode.Tag              = db;
                dbNode.ToolTipText      = string.IsNullOrEmpty(db.Comment) ? db.Name : db.Comment;
                dbNode.ContextMenuStrip = cmsDatabase;
                root.Nodes.Add(dbNode);

                MainForm.AddDbListItem(db);
            }

            root.Expand();
        }
Exemple #3
0
        /// <summary>
        /// 创建一个数据提供程序实例
        /// </summary>
        /// <param name="connectionStringName"></param>
        /// <returns></returns>
        public static Database Create(string connectionStringName)
        {
            CheckUtil.ArgumentNotNullOrEmpty(connectionStringName, "connectionStringName");
            DbConnDAL dal = new DbConnDAL();

            var model = dal.FindOne(connectionStringName);

            if (model == null)
            {
                throw new Exception(string.Format(Resources.Data.ConnectionStringNameNotFound, connectionStringName));
            }

            string            connectionString = model.ConnectionString;
            string            providerName     = model.ProviderName;
            Database          db = new SqlServerDatabase(connectionString);
            DbProviderFactory providerFactory = null;

            if (string.IsNullOrEmpty(providerName))
            {
                return(db);
            }

            //if (css.ProviderName == "System.Data.OleDb")
            //{
            //    providerFactory = OleDbFactory.Instance;
            //}
            //else
            //{
            //    providerFactory = DbProviderFactories.GetFactory(css.ProviderName);
            //}
            //if (providerFactory == null) throw new Exception(string.Format(Resources.Data.DataProviderNotFound, css.ProviderName));

            switch (providerName)
            {
            //case "System.Data.SqlClient":
            //    break;
            case "System.Data.Odbc":
                db = new OdbcDatabase(connectionString);
                break;

            case "System.Data.OleDb":
                db = new OleDbDatabase(connectionString);
                break;

            case "System.Data.OracleClient":
                db = new OracleDatabase(connectionString);
                break;

            case "Oracle.ManagedDataAccess.Client":
                db = new OracleDatabase(connectionString);
                break;

            case "Devart.Data.Oracle": //http://evget.com/zh-CN/product/954/feature.aspx  http://www.devart.com/
            case "DDTek.Oracle":       //http://www.datadirect.com/index.html 由于删除了版权DLL,导致该功能可能无法使用。可在QQ群:122161138中下载source_lib.zip
                providerFactory = DbProviderFactories.GetFactory(providerName);
                db = new OracleDatabase(connectionString, providerFactory);
                break;

            case "System.Data.SQLite":
                providerFactory = DbProviderFactories.GetFactory(providerName);
                db = new SQLiteDatabase(connectionString, providerFactory);
                break;

            case "MySql.Data.MySqlClient":
                providerFactory = DbProviderFactories.GetFactory(providerName);
                db = new MySqlDatabase(connectionString, providerFactory);
                break;

            case "IBM.Data.DB2":
                providerFactory = DbProviderFactories.GetFactory(providerName);
                db = new DB2Database(connectionString, providerFactory);
                break;

            case "FirebirdSql.Data.FirebirdClient":
                providerFactory = DbProviderFactories.GetFactory(providerName);
                db = new FirebirdDatabase(connectionString, providerFactory);
                break;

            default:
                break;
            }

            return(db);
        }