/[AnywhereTS-MSSQL]/trunk/AnywhereTS.DBSupport/DBConnector.cs
ViewVC logotype

Diff of /trunk/AnywhereTS.DBSupport/DBConnector.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 128 by william, Sat Jul 14 13:01:52 2012 UTC revision 132 by william, Sun Jul 15 03:09:38 2012 UTC
# Line 17  namespace AnywhereTS.DBSupport Line 17  namespace AnywhereTS.DBSupport
17          where DBDataAdapter : DbDataAdapter, new()          where DBDataAdapter : DbDataAdapter, new()
18      {      {
19          bool ConnectionIsOpen { get; }          bool ConnectionIsOpen { get; }
20          void CreateConnection(out Exception ErrorInfo);          DBConnection CreateConnection(out Exception ErrorInfo);
21          void OpenConnection(out Exception ErrorInfo);          void OpenConnection(out Exception ErrorInfo);
22          void CloseConnection(out Exception ErrorInfo);          void CloseConnection(out Exception ErrorInfo);
23    
# Line 25  namespace AnywhereTS.DBSupport Line 25  namespace AnywhereTS.DBSupport
25          void ExecuteNonQuery(string command, List<DBParameter> Params, out Exception ErrorInfo);          void ExecuteNonQuery(string command, List<DBParameter> Params, out Exception ErrorInfo);
26          List<string> ExecuteColumnNamesReader(string command, List<DBParameter> Params, out Exception ErrorInfo);          List<string> ExecuteColumnNamesReader(string command, List<DBParameter> Params, out Exception ErrorInfo);
27    
28          DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo);          //DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo);
29          bool RunScript(string strFile, out Exception ErrorInfo);          bool RunScript(string strFile, out Exception ErrorInfo);
30      }      }
31      public abstract class DBConnector<DBParameter, DBCommand, DBConnection, DBDataAdapter> :      public abstract class DBConnector<DBParameter, DBCommand, DBConnection, DBDataAdapter> :
# Line 65  namespace AnywhereTS.DBSupport Line 65  namespace AnywhereTS.DBSupport
65          public virtual bool ConnectionIsOpen { get; protected set; }          public virtual bool ConnectionIsOpen { get; protected set; }
66          #endregion          #endregion
67          #region public virtual DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo)          #region public virtual DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo)
68          public virtual DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo)          //public virtual DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo)
69          {          //{
70              ErrorInfo = null;          //    ErrorInfo = null;
71              try          //    try
72              {          //    {
73                  command = this.SafeSqlLiteral(command);          //        command = this.SafeSqlLiteral(command);
74                  DBCommand sqlComm = new DBCommand();          //        DBCommand sqlComm = new DBCommand();
75                  sqlComm.CommandText = command;          //        sqlComm.CommandText = command;
76                  sqlComm.Connection = connection;          //        sqlComm.Connection = connection;
77                  foreach (DBParameter p in Params) { sqlComm.Parameters.Add(p); }          //        foreach (DBParameter p in Params) { sqlComm.Parameters.Add(p); }
78                  return sqlComm;          //        return sqlComm;
79              }          //    }
80              catch (SqlException ex)          //    catch (SqlException ex)
81              {          //    {
82                  SqlException e = (ex.GetBaseException() as SqlException);          //        SqlException e = (ex.GetBaseException() as SqlException);
83                  using (log4net.NDC.Push(string.Format("SqlException: ID={0} MESSAGE={1}{2}Diagnostics:{2}{3}", e.Number.ToString(), e.Message, System.Environment.NewLine, e.ToString())))          //        using (log4net.NDC.Push(string.Format("SqlException: ID={0} MESSAGE={1}{2}Diagnostics:{2}{3}", e.Number.ToString(), e.Message, System.Environment.NewLine, e.ToString())))
84                  {          //        {
85                      Logging.DatabaseLog.Error(string.Format("Failed to create command instance using command: {0}", command));          //            Logging.DatabaseLog.Error(string.Format("Failed to create command instance using command: {0}", command));
86                  }          //        }
87                  ErrorInfo = ex; throw ErrorInfo;          //        ErrorInfo = ex; throw ErrorInfo;
88              }          //    }
89              catch (Exception ex)          //    catch (Exception ex)
90              {          //    {
91                  Exception e = ex.GetBaseException();          //        Exception e = ex.GetBaseException();
92                  using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", e.GetType().Name, e.Message, System.Environment.NewLine, e.ToString())))          //        using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", e.GetType().Name, e.Message, System.Environment.NewLine, e.ToString())))
93                  {          //        {
94                      Logging.DatabaseLog.Error(string.Format("Failed to create command instance using command: {0}", command));          //            Logging.DatabaseLog.Error(string.Format("Failed to create command instance using command: {0}", command));
95                  }          //        }
96                  ErrorInfo = ex; throw ErrorInfo;          //        ErrorInfo = ex; throw ErrorInfo;
97              }          //    }
98          }          //}
99          #endregion          #endregion
100          #region  public virtual void CreateConnection(out Exception ErrorInfo)          #region  public virtual DBConnection CreateConnection(out Exception ErrorInfo)
101          public virtual void CreateConnection(out Exception ErrorInfo)          public virtual DBConnection CreateConnection(out Exception ErrorInfo)
102          {          {
103              ErrorInfo = null;              ErrorInfo = null;
104              string connetionString = string.Empty;              string connetionString = string.Empty;
# Line 112  namespace AnywhereTS.DBSupport Line 112  namespace AnywhereTS.DBSupport
112                      connection.ConnectionString = connetionString;                      connection.ConnectionString = connetionString;
113                      Logging.DatabaseLog.Debug("Created Connection");                      Logging.DatabaseLog.Debug("Created Connection");
114                  }                  }
115                    return this.connection;
116              }              }
117              catch (SqlException ex)              catch (SqlException ex)
118              {              {
# Line 151  namespace AnywhereTS.DBSupport Line 152  namespace AnywhereTS.DBSupport
152              //catch (SqlException ex) { Console.WriteLine(ex.ToString()); ErrorInfo = ex;  throw ErrorInfo;}              //catch (SqlException ex) { Console.WriteLine(ex.ToString()); ErrorInfo = ex;  throw ErrorInfo;}
153              catch (SqlException ex)              catch (SqlException ex)
154              {              {
155                    if (ex.Message.ToLower().Contains(string.Format("Cannot open database").ToLower()))
156                    {
157                        ErrorInfo = null;
158                        return;
159                    }
160                  using (log4net.NDC.Push(string.Format("SqlException: ID={0} MESSAGE={1}{2}Diagnostics:{2}{3}", ex.Number.ToString(), ex.Message, System.Environment.NewLine, ex.ToString())))                  using (log4net.NDC.Push(string.Format("SqlException: ID={0} MESSAGE={1}{2}Diagnostics:{2}{3}", ex.Number.ToString(), ex.Message, System.Environment.NewLine, ex.ToString())))
161                  {                  {
162                      Logging.DatabaseLog.Error(string.Format("Failed to open connection to {0} Database", DBDatabase));                      Logging.DatabaseLog.Error(string.Format("Failed to open connection to {0} Database", DBDatabase));
# Line 159  namespace AnywhereTS.DBSupport Line 165  namespace AnywhereTS.DBSupport
165              }              }
166              catch (Exception ex)              catch (Exception ex)
167              {              {
168                    if (ex.Message.ToLower().Contains(string.Format("Cannot open database").ToLower()))
169                    {
170                        ErrorInfo = null;
171                        return;
172                    }
173                  using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))                  using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", ex.GetType().Name, ex.Message, System.Environment.NewLine, ex.ToString())))
174                  {                  {
175                      Logging.DatabaseLog.Error(string.Format("Failed to open connection to {0} Database", DBDatabase));                      Logging.DatabaseLog.Error(string.Format("Failed to open connection to {0} Database", DBDatabase));
# Line 356  namespace AnywhereTS.DBSupport Line 367  namespace AnywhereTS.DBSupport
367              try              try
368              {              {
369                  Exception ErrorInfo;                  Exception ErrorInfo;
370                  CloseConnection(out ErrorInfo);                  if (this.ConnectionIsOpen)
371                        CloseConnection(out ErrorInfo);
372              }              }
373              catch              catch
374              {              {

Legend:
Removed from v.128  
changed lines
  Added in v.132

  ViewVC Help
Powered by ViewVC 1.1.22