Example #1
0
 public bool isConnected()
 {
     if (this.isconnected)
     {
         TimeSpan newtime = DateTime.Now - tick;
         if (newtime.TotalMinutes > 5)
         {
             MSSQLOperator tmp;
             Logger.ShowSQL("UserDB:Pinging SQL Server to keep the connection alive", null);
             tmp = dbinactive;
             if (tmp.State == ConnectionState.Open)
             {
                 tmp.Close();
             }
             tmp.Open();
             dbinactive = db;
             db         = tmp;
             tick       = DateTime.Now;
         }
         if (db.State == System.Data.ConnectionState.Broken || db.State == System.Data.ConnectionState.Closed)
         {
             this.isconnected = false;
         }
     }
     return(this.isconnected);
 }
Example #2
0
 public MSSQLUserDB(string host, int port, string database, string user, string pass)
 {
     this.host        = host;
     this.port        = port;
     this.user        = user;
     this.pass        = pass;
     this.database    = database;
     this.isconnected = false;
     try
     {
         db         = new MSSQLOperator(string.Format("Server={1};Uid={2};Pwd={3};Database={0};", database, host, user, pass));
         dbinactive = new MSSQLOperator(string.Format("Server={1};Uid={2};Pwd={3};Database={0};", database, host, user, pass));
         db.Open();
     }
     catch (Exception ex)
     {
         Logger.ShowSQL("Connction fails, connection string:" + string.Format("Server={1};Uid={2};Pwd={3};Database={0};", database, host, user, pass), null);
         Logger.ShowSQL(ex, null);
     }
     if (db != null)
     {
         if (db.State != ConnectionState.Closed)
         {
             this.isconnected = true;
         }
         else
         {
             Console.WriteLine("SQL Connection error");
         }
     }
 }
Example #3
0
 public MSSQLCharacterDB( string host, int port, string database, string user, string pass )
 {
     this.host = host;
     this.port = port.ToString();
     this.dbuser = user;
     this.dbpass = pass;
     this.database = database;
     this.isconnected = false;
     try
     {
         db = new MSSQLOperator(string.Format("Server={1};Uid={2};Pwd={3};Database={0};", database, host, user, pass));
         dbinactive = new MSSQLOperator(string.Format("Server={1};Uid={2};Pwd={3};Database={0};", database, host, user, pass));
         db.Open();
     }
     catch (Exception ex)
     {
         Logger.ShowSQL("Connction fails, connection string:" + string.Format("Server={1};Uid={2};Pwd={3};Database={0};", database, host, user, pass), null);
         Logger.ShowSQL(ex, null);
     }
     if( db != null ) { if( db.State != ConnectionState.Closed )this.isconnected = true; else { Console.WriteLine( "SQL Connection error" ); } }
 }
Example #4
0
 public bool isConnected()
 {
     if( this.isconnected )
     {
         TimeSpan newtime = DateTime.Now - tick;
         if (newtime.TotalMinutes > 5)
         {
             MSSQLOperator tmp;
             Logger.ShowSQL("ActorDB:Pinging SQL Server to keep the connection alive", null);
             tmp = dbinactive;
             if (tmp.State == ConnectionState.Open) tmp.Close();
             tmp.Open();
             dbinactive = db;
             db = tmp;
             tick = DateTime.Now;
         }
         if( db.State == System.Data.ConnectionState.Broken || db.State == System.Data.ConnectionState.Closed )
         {
             this.isconnected = false;
         }
     }
     return this.isconnected;
 }