Exemple #1
0
 public void Connect()
 {
     try
     {
         if (AdoCon.State == ConnectionState.Open)
         {
             Close();
         }
         AdoCon.ConnectionString = "Server=" + Server.Replace(".local", "") + ";Initial Catalog=" + DataBase + ";User Id=" + User + ";Password="******";MultipleActiveResultSets=True;";
         AdoCon.Open();
         if (context_info != null)
         {
             SqlCommand cmd  = AdoCon.CreateCommand();
             string     lSql = "set CONTEXT_INFO @C";
             cmd.CommandText = lSql;
             SqlParameter param = new SqlParameter();
             param.ParameterName = "@C";
             param.DbType        = DbType.Binary;
             param.Size          = 127;
             param.Value         = context_info;
             cmd.Parameters.Add(param);
             cmd.ExecuteNonQuery();
         }
     }
     catch
     {
         throw;
     }
 }
Exemple #2
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    AdoCon.Close();
                    AdoCon.Dispose();
                    IP      = null;
                    oServer = null;
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
Exemple #3
0
        public async override Task ConnectAsync()
        {
            try
            {
                if (AdoCon.State == ConnectionState.Open)
                {
                    Close();
                }
                string newConnectionString = "";
                if (User != "SSPI")
                {
                    newConnectionString = "Server=" + Server.Replace(".local", "") + ";Initial Catalog=" + DataBase + ";User Id=" + User + ";Password="******";MultipleActiveResultSets=True;Connection Lifetime=3;Max Pool Size=3";
                }
                else
                {
                    newConnectionString = "Server=" + Server.Replace(".local", "") + ";Initial Catalog=" + DataBase + ";Integrated Security=SSPI;MultipleActiveResultSets=True;Connection Lifetime=3;Max Pool Size=3";
                }
                if (newConnectionString != AdoCon.ConnectionString)
                {
                    AdoCon.ConnectionString = newConnectionString;
                }
                await AdoCon.OpenAsync();

                if (context_info != null)
                {
                    SqlCommand cmd  = AdoCon.CreateCommand();
                    string     lSql = "set CONTEXT_INFO @C";
                    cmd.CommandText = lSql;
                    SqlParameter param = new SqlParameter();
                    param.ParameterName = "@C";
                    param.DbType        = DbType.Binary;
                    param.Size          = 127;
                    param.Value         = context_info;
                    cmd.Parameters.Add(param);
                    await cmd.ExecuteNonQueryAsync();
                }
            }
            catch
            {
                throw;
            }
        }
Exemple #4
0
 public override void Connect()
 {
     try
     {
         if (AdoCon.State == ConnectionState.Open)
         {
             Close();
         }
         string newConnectionString = "";
         if (User != "SSPI")
         {
             newConnectionString = string.Format("Server={0};Initial Catalog={1};User Id={2};Password={3};MultipleActiveResultSets=True;Connection Lifetime=3;Max Pool Size=3", Server, DataBase, User, Password);
         }
         else
         {
             newConnectionString = string.Format("Server={0};Initial Catalog={1};Integrated Security=SSPI;MultipleActiveResultSets=True;Connection Lifetime=3;Max Pool Size=3", Server, DataBase);
         }
         if (newConnectionString != AdoCon.ConnectionString)
         {
             AdoCon.ConnectionString = newConnectionString;
         }
         AdoCon.Open();
         if (context_info != null)
         {
             SqlCommand cmd  = AdoCon.CreateCommand();
             string     lSql = "set CONTEXT_INFO @C";
             cmd.CommandText = lSql;
             SqlParameter param = new SqlParameter();
             param.ParameterName = "@C";
             param.DbType        = DbType.Binary;
             param.Size          = 128;
             param.Value         = context_info;
             cmd.Parameters.Add(param);
             cmd.ExecuteNonQuery();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #5
0
 public void Close()
 {
     AdoCon.Close();
 }
Exemple #6
0
 public override void Close()
 {
     AdoCon.Close();
 }