コード例 #1
0
        private bool TestConnetDataBaseButNotSave(string ip, string account, string password)
        {
            bool connetSuccess = true;

            try
            {
                DbUtility dbUtility       = DbUtilityCreator.GetDefaultDbUtility();
                DbUtility dbUtilityToTest = null;

                SQLConnModel sqlConnModel = dbUtility.SqlconModel;
                sqlConnModel.DBIP     = ip;
                sqlConnModel.DBUser   = account;
                sqlConnModel.DBPasswd = password;

                dbUtilityToTest = new DbUtility(sqlConnModel, dbUtility.DbProviderType);

                connetSuccess = dbUtilityToTest.TestConnection();

                if (connetSuccess)
                {
                    this.sqlConnModel = sqlConnModel;
                }
            }
            catch (Exception)
            {
                connetSuccess = false;
                throw;
            }

            return(connetSuccess);
        }
コード例 #2
0
        //public DbUtility(string connectionString, DbProviderType dbProviderType)
        //{
        //    ConnectionString = connectionString;
        //    providerFactory = ProviderFactory.GetDbProviderFactory(dbProviderType);
        //    if (providerFactory == null)
        //    {
        //        throw new ArgumentException("Can't load DbProviderFactory for given value of providerType");
        //    }
        //}

        public DbUtility(SQLConnModel sqlconModel, DbProviderType dbProviderType)
        {
            this.SqlconModel    = sqlconModel;
            this.DbProviderType = dbProviderType;

            string conStr = null;

            switch (dbProviderType)
            {
            case DbProviderType.MySql:
                conStr           = "server = " + sqlconModel.DBIP + ";uid = " + sqlconModel.DBUser + ";pwd = " + sqlconModel.DBPasswd + ";database = " + sqlconModel.DBName;
                ConnectionString = conStr;
                providerFactory  = ProviderFactory.GetDbProviderFactory(dbProviderType);

                if (providerFactory == null)
                {
                    throw new ArgumentException("Can't load DbProviderFactory for given value of providerType");
                }
                break;

            case DbProviderType.SqlServer:
                conStr = "Data Source= " + sqlconModel.DBIP + "; Initial Catalog = " + sqlconModel.DBName +
                         "; User ID = " + sqlconModel.DBUser + "; Password = "******"Can't load DbProviderFactory for given value of providerType");
                }
                break;
            }
        }
コード例 #3
0
        public static DbUtility GetDbUtility(DbProviderType dbProviderType)
        {
            if (null == dbUtility)
            {
                SQLConnectControl sqlConnectControl = new SQLConnectControl();
                SQLConnModel      sqlConn           = new SQLConnModel();

                sqlConn   = sqlConnectControl.InitConnectConfigDB();
                dbUtility = new DbUtility(sqlConn, dbProviderType);
            }

            return(dbUtility);
        }
コード例 #4
0
        public static DbUtility GetDefaultDbUtility()
        {
            if (null == dbUtility)
            {
                SQLConnectControl sqlConnectControl = new SQLConnectControl();
                SQLConnModel      sqlConnModel      = new SQLConnModel();

                sqlConnModel = sqlConnectControl.InitConnectConfigDB();
                dbUtility    = new DbUtility(sqlConnModel, DbProviderType.MySql);
            }

            return(dbUtility);
        }