示例#1
0
        public SQLConnObj TestConnection(string server, string database, string user, string password)
        {
            SQLConnObj sqlconnobj = new SQLConnObj();

            sqlconnobj.isConnect = false;
            try
            {
                SqlConnection conn = new SqlConnection();
                SqlConnectionStringBuilder sqlconnstr = new SqlConnectionStringBuilder();
                sqlconnstr.IntegratedSecurity = false;
                sqlconnstr.DataSource         = server;
                sqlconnstr.InitialCatalog     = database;
                sqlconnstr.UserID             = user;
                sqlconnstr.Password           = password;

                conn.ConnectionString = sqlconnstr.ToString();

                conn.Open();
                sqlconnobj.isConnect = true;
                conn.Close();
            }
            catch (SqlException sqlexp)
            {
                //MessageBox.Show("SqlConnection Exception: " + sqlexp.Message);
                sqlconnobj.exp = sqlexp;
            }
            return(sqlconnobj);
        }
示例#2
0
        public SQLConnObj Connection(string server, string database, string user, string password)
        {
            SQLConnObj sqlconnobj = new SQLConnObj();

            sqlconnobj.isConnect = false;
            try
            {
                _sqlconn    = new SqlConnection();
                _sqlconnstr = new SqlConnectionStringBuilder();
                _sqlconnstr.IntegratedSecurity = false;
                _sqlconnstr.DataSource         = server;
                _sqlconnstr.InitialCatalog     = database;
                _sqlconnstr.UserID             = user;
                _sqlconnstr.Password           = password;
                _sqlconn.ConnectionString      = _sqlconnstr.ToString();
                _sqlconn.Open();
                sqlconnobj.isConnect = true;
            }
            catch (SqlException sqlexp)
            {
                sqlconnobj.exp = sqlexp;
            }
            return(sqlconnobj);
        }