示例#1
0
        //数据库连接
        public bool sqlOpen(object sServer1)
        {
            String sServer     = Convert.ToString(sServer1);
            String strServer   = new clsIni().IniReadValue("Server", sServer);
            String strDatabase = new clsIni().IniReadValue("Database", sServer);
            String strUserID   = new clsIni().IniReadValue("UserName", sServer);
            String strPassword = new clsIni().IniReadValue("Password", sServer);
            String strCon      = "server=" + strServer + ";database=" + strDatabase + ";uid=" + strUserID + ";pwd=" + new clsSqlPassword().OutPassword(strPassword);

            sqlCon = new SqlConnection(strCon);
            try
            {
                sqlCon.Open();//打开连接
                return(true);
            }
            catch (Exception ex)
            {
                DialogResult r = MessageBox.Show("数据库连接失败!是否重新配置服务器!\n" + ex.Message, "提示!", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (r == DialogResult.OK)
                {
                    SqlFile.frmConfig frmConfig1 = new frmConfig();
                    frmConfig1.sServer = sServer;
                    frmConfig1.ShowDialog();
                }
                return(false);
            }
        }
示例#2
0
        //数据库连接
        public bool sqlOpen(object sServer1)
        {
            //threadLoading = new Thread(new ThreadStart(s));
            //threadLoading.IsBackground = true;
            ////threadLoading.Priority = ThreadPriority.AboveNormal;
            //threadLoading.Start();
            String sServer     = Convert.ToString(sServer1);
            String strServer   = new clsIni().IniReadValue("Server", sServer);
            String strDatabase = new clsIni().IniReadValue("Database", sServer);
            String strUserID   = new clsIni().IniReadValue("UserName", sServer);
            String strPassword = new clsIni().IniReadValue("Password", sServer);
            String strCon      = "server=" + strServer + ";database=" + strDatabase + ";uid=" + strUserID + ";pwd=" + new clsSqlPassword().OutPassword(strPassword);

            sqlCon = new SqlConnection(strCon);
            try
            {
                sqlCon.Open();//打开连接
                return(true);
            }
            catch (Exception ex)
            {
                //if (frmLoading1.InvokeRequired)//判断是否有其他线程想访问
                //{
                //    Action act = () => { frmLoading1.Close(); };//封装一个窗体关闭的方法
                //    frmLoading1.Invoke(act);//在拥有该控件的线程上执行该方法
                //}
                //if (threadLoading != null)
                //    threadLoading.Abort();
                DialogResult r = MessageBox.Show("数据库连接失败!是否重新配置服务器!\n" + ex.Message, "提示!", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (r == DialogResult.OK)
                {
                    SqlFile.frmConfig frmConfig1 = new frmConfig();
                    frmConfig1.sServer = sServer;
                    frmConfig1.ShowDialog();
                }
                return(false);
            }
        }