Exemplo n.º 1
0
        public DataExport(string longservername, string dbname)
        {
            InitializeComponent();
            DbName             = dbname;
            dbset              = Maticsoft.CmConfig.DbConfig.GetSetting(longservername);
            dbobj              = Maticsoft.DBFactory.DBOMaker.CreateDbObj(dbset.DbType);
            dbobj.DbConnectStr = dbset.ConnectStr;
            cb  = new Maticsoft.CodeBuild.CodeBuilders(dbobj);
            dsb = Maticsoft.DBFactory.DBOMaker.CreateScript(dbset.DbType);// ObjHelper.CreatDsb(longservername);

            this.lblServer.Text = dbset.Server;
        }
Exemplo n.º 2
0
        private void btn_Ok_Click(object sender, System.EventArgs e)
        {
            try
            {
                string server = this.txtServer.Text.Trim();
                string user   = this.txtUser.Text.Trim();
                string pass   = this.txtPass.Text.Trim();

                if (this.radBtn_DB.Checked)
                {
                    GetConstr();
                    if (server == "")
                    {
                        MessageBox.Show(this, "数据库不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }

                if (this.radBtn_Constr.Checked)
                {
                    if (txtConstr.Text == "")
                    {
                        MessageBox.Show(this, "数据库不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
                string constr = this.txtConstr.Text;

                //测试连接
                OleDbConnection myCn = new OleDbConnection(constr);
                try
                {
                    this.Text = "正在连接数据库,请稍候...";
                    myCn.Open();
                }
                catch
                {
                    this.Text = "连接数据库失败!";
                    MessageBox.Show(this, "连接数据库失败!请检查数据库地址或用户名密码是否正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                myCn.Close();
                this.Text = "连接数据库成功!";

                if (dbobj == null)
                {
                    dbobj = new Maticsoft.CmConfig.DbSettings();
                }

                //将当前配置写入配置文件
                dbobj.DbType     = "OleDb";
                dbobj.Server     = server;
                dbobj.ConnectStr = constr;
                dbobj.DbName     = "";
                Maticsoft.CmConfig.DbConfig.AddSettings(dbobj);

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(this, ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                LogInfo.WriteLog(ex);
            }
        }
Exemplo n.º 3
0
 private void CreatDbObj(string servername)
 {
     Maticsoft.CmConfig.DbSettings dbset = Maticsoft.CmConfig.DbConfig.GetSetting(servername);
     dbobj = Maticsoft.DBFactory.DBOMaker.CreateDbObj(dbset.DbType);
     dbobj.DbConnectStr = dbset.ConnectStr;
 }