Example #1
0
        private bool TestMSSQLConnection(out string errMsg)
        {
            errMsg = string.Empty;
            SqlConnectionStringBuilder sqlConnBuilder = new SqlConnectionStringBuilder();

            sqlConnBuilder.DataSource     = this.Server;
            sqlConnBuilder.InitialCatalog = this.Database;
            sqlConnBuilder.UserID         = this.UserName;
            sqlConnBuilder.Password       = this.Password;
            OPCMSSQLHelper sqlHelper = new OPCMSSQLHelper(sqlConnBuilder.ConnectionString, out errMsg);

            try
            {
                sqlHelper.Connected = true;
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return(false);
            }

            string    querClause = string.Format("SELECT TOP 1 * FROM {0}", TableName);
            DataTable dt         = sqlHelper.QueryRecords(querClause, out errMsg);

            if (dt == null)
            {
                return(false);
            }

            querClause = string.Format("SELECT TOP 1 * FROM {0}", HistoryTableName);
            dt         = sqlHelper.QueryRecords(querClause, out errMsg);
            return(dt != null);
        }
Example #2
0
        public override bool CreateConnection(out string errMsg)
        {
            errMsg = string.Empty;
            SqlConnectionStringBuilder sqlConnBuilder = new SqlConnectionStringBuilder();

            sqlConnBuilder.DataSource     = this.m_server;
            sqlConnBuilder.InitialCatalog = this.m_database;
            sqlConnBuilder.UserID         = this.m_userName;
            sqlConnBuilder.Password       = this.m_password;
            this.m_sqlHelper = new OPCMSSQLHelper(sqlConnBuilder.ConnectionString, out errMsg);
            try
            {
                this.m_sqlHelper.Connected = true;
                this.m_sqlHelper.Connected = false;
                return(true);
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                OPCLog.Error(string.Format("创建 MS SQL Server 数据库连接时发生错误:{0}", errMsg));
                return(false);
            }
        }