/[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 87 by william, Fri Jul 13 22:37:40 2012 UTC revision 116 by william, Sat Jul 14 08:03:33 2012 UTC
# Line 24  namespace AnywhereTS.DBSupport Line 24  namespace AnywhereTS.DBSupport
24          List<string> ExecuteColumnNamesReader(string command, List<DBParameter> Params, out Exception ErrorInfo);          List<string> ExecuteColumnNamesReader(string command, List<DBParameter> Params, out Exception ErrorInfo);
25    
26          DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo);          DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo);
27          public bool RunScript(string strFile, MsSqlConnector con, out Exception ErrorInfo);          bool RunScript(string strFile, out Exception ErrorInfo);
28      }      }
29      public abstract class DBConnector<DBParameter, DBCommand, DBConnection, DBDataAdapter> :      public abstract class DBConnector<DBParameter, DBCommand, DBConnection, DBDataAdapter> :
30          IDBConnector<DBParameter, DBCommand, DBConnection, DBDataAdapter>          IDBConnector<DBParameter, DBCommand, DBConnection, DBDataAdapter>
# Line 34  namespace AnywhereTS.DBSupport Line 34  namespace AnywhereTS.DBSupport
34          where DBDataAdapter : DbDataAdapter, new()          where DBDataAdapter : DbDataAdapter, new()
35      {      {
36    
37          public DBConnector(string DBServerAddress, string DBServerInstance, string DBDatabase)          public DBConnector(string Server, string Instance, string Database)
38          {          {
39              this.DBServerAddress = DBServerAddress;              DBServerAddress = Server;
40              this.DBServerInstance = DBServerInstance;              DBServerInstance = Instance;
41              this.DBDatabase = DBDatabase;              DBDatabase = Database;
42                using (log4net.NDC.Push(string.Format("[Server={0}] [Instance={1}] [Database={2}]", Server, Instance, Database)))
43                {
44                    Logging.DatabaseLog.Debug("Creating DBConnector instance");
45                }
46          }          }
47    
48            public static string GetConnectionString()
49            {
50                return string.Format(@"Data Source={0}\{1};Initial Catalog={2};Integrated Security=SSPI", DBServerAddress, DBServerInstance, DBDatabase);
51            }
52          protected DBConnection connection;          protected DBConnection connection;
53          protected string DBServerAddress = "";          #region DBServerAddress, DBServerInstance, DBDatabase
54          protected string DBServerInstance = "";          internal static string DBServerAddress = "";
55          protected string DBDatabase = "";          internal static string DBServerInstance = "";
56            internal static string DBDatabase = "";
57            #endregion
58            #region  private string SafeSqlLiteral(string inputSQL)
59          private string SafeSqlLiteral(string inputSQL) { return inputSQL.Replace("'", "''"); }          private string SafeSqlLiteral(string inputSQL) { return inputSQL.Replace("'", "''"); }
60            #endregion
61          #region IDBConnector members          #region IDBConnector members
62          public DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo)          #region  public virtual bool ConnectionIsOpen
63            public virtual bool ConnectionIsOpen { get; protected set; }
64            #endregion
65            #region public virtual DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo)
66            public virtual DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo)
67          {          {
68              ErrorInfo = null;              ErrorInfo = null;
69              try              try
# Line 74  namespace AnywhereTS.DBSupport Line 90  namespace AnywhereTS.DBSupport
90                      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));
91                  }                  }
92                  ErrorInfo = ex; throw ErrorInfo;                  ErrorInfo = ex; throw ErrorInfo;
93              }              }
94          }          }
95          private bool _ConnectionIsOpen;          #endregion
96          public virtual bool ConnectionIsOpen { get { return _ConnectionIsOpen; } protected set { _ConnectionIsOpen = value; } }          #region  public virtual void CreateConnection(out Exception ErrorInfo)
97          public virtual void CreateConnection(out Exception ErrorInfo)          public virtual void CreateConnection(out Exception ErrorInfo)
98          {          {
99              ErrorInfo = null;              ErrorInfo = null;
100              try              try
101              {              {
102                  string connetionString = null;                  string connetionString = null;
103                  connetionString = string.Format(@"Data Source={0}\{1};Initial Catalog={2};Integrated Security=SSPI", DBServerAddress, DBServerInstance, DBDatabase);                  connetionString = GetConnectionString();
104                  connection = new DBConnection();                  connection = new DBConnection();
105                  connection.ConnectionString = connetionString;                  connection.ConnectionString = connetionString;
106              }              }
# Line 103  namespace AnywhereTS.DBSupport Line 119  namespace AnywhereTS.DBSupport
119                      Logging.DatabaseLog.Error(string.Format("Failed to create connection to {0} Database", DBDatabase));                      Logging.DatabaseLog.Error(string.Format("Failed to create connection to {0} Database", DBDatabase));
120                  }                  }
121                  ErrorInfo = ex; throw ErrorInfo;                  ErrorInfo = ex; throw ErrorInfo;
122              }              }
123          }          }
124            #endregion
125            #region public virtual void OpenConnection(out Exception ErrorInfo)
126          public virtual void OpenConnection(out Exception ErrorInfo)          public virtual void OpenConnection(out Exception ErrorInfo)
127          {          {
128              ErrorInfo = null;              ErrorInfo = null;
# Line 130  namespace AnywhereTS.DBSupport Line 148  namespace AnywhereTS.DBSupport
148                      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));
149                  }                  }
150                  ErrorInfo = ex; throw ErrorInfo;                  ErrorInfo = ex; throw ErrorInfo;
151              }              }
152          }          }
153            #endregion
154            #region public virtual void CloseConnection(out Exception ErrorInfo)
155          public virtual void CloseConnection(out Exception ErrorInfo)          public virtual void CloseConnection(out Exception ErrorInfo)
156          {          {
157              ErrorInfo = null;              ErrorInfo = null;
# Line 155  namespace AnywhereTS.DBSupport Line 175  namespace AnywhereTS.DBSupport
175                      Logging.DatabaseLog.Error(string.Format("Failed to close connection to {0} Database", DBDatabase));                      Logging.DatabaseLog.Error(string.Format("Failed to close connection to {0} Database", DBDatabase));
176                  }                  }
177                  ErrorInfo = ex; throw ErrorInfo;                  ErrorInfo = ex; throw ErrorInfo;
178              }              }
179          }          }
180            #endregion
181            #region public virtual DbDataReader ExecuteQuery(string command, List<DBParameter> Params, out Exception ErrorInfo)
182          public virtual DbDataReader ExecuteQuery(string command, List<DBParameter> Params, out Exception ErrorInfo)          public virtual DbDataReader ExecuteQuery(string command, List<DBParameter> Params, out Exception ErrorInfo)
183          {          {
184              ErrorInfo = null;              ErrorInfo = null;
# Line 187  namespace AnywhereTS.DBSupport Line 208  namespace AnywhereTS.DBSupport
208                      Logging.DatabaseLog.Error(string.Format("Failed to execute querey: {0}", command));                      Logging.DatabaseLog.Error(string.Format("Failed to execute querey: {0}", command));
209                  }                  }
210                  ErrorInfo = ex; throw ErrorInfo;                  ErrorInfo = ex; throw ErrorInfo;
211              }              }
212          }          }
213            #endregion
214            #region public virtual void ExecuteNonQuery(string command, List<DBParameter> Params, out Exception ErrorInfo)
215          public virtual void ExecuteNonQuery(string command, List<DBParameter> Params, out Exception ErrorInfo)          public virtual void ExecuteNonQuery(string command, List<DBParameter> Params, out Exception ErrorInfo)
216          {          {
217              ErrorInfo = null;              ErrorInfo = null;
# Line 217  namespace AnywhereTS.DBSupport Line 240  namespace AnywhereTS.DBSupport
240                      Logging.DatabaseLog.Error(string.Format("Failed to execute non querey: {0}", command));                      Logging.DatabaseLog.Error(string.Format("Failed to execute non querey: {0}", command));
241                  }                  }
242                  ErrorInfo = ex; throw ErrorInfo;                  ErrorInfo = ex; throw ErrorInfo;
243              }                  }
244          }          }
245            #endregion
246            #region public virtual List<string> ExecuteColumnNamesReader(string command, List<DBParameter> Params, out Exception ErrorInfo)
247          public virtual List<string> ExecuteColumnNamesReader(string command, List<DBParameter> Params, out Exception ErrorInfo)          public virtual List<string> ExecuteColumnNamesReader(string command, List<DBParameter> Params, out Exception ErrorInfo)
248          {          {
249              ErrorInfo = null;              ErrorInfo = null;
# Line 258  namespace AnywhereTS.DBSupport Line 283  namespace AnywhereTS.DBSupport
283                      Logging.DatabaseLog.Error(string.Format("Failed to get colum names from reader: {0}", command));                      Logging.DatabaseLog.Error(string.Format("Failed to get colum names from reader: {0}", command));
284                  }                  }
285                  ErrorInfo = ex; throw ErrorInfo;                  ErrorInfo = ex; throw ErrorInfo;
286              }                          }
287          }          }
288            #endregion
289            #region public string[] ParseScriptToCommands(string strScript)
290          public string[] ParseScriptToCommands(string strScript)          public string[] ParseScriptToCommands(string strScript)
291          {          {
292              string[] commands;              string[] commands;
293              commands = Regex.Split(strScript, "GO\r\n", RegexOptions.IgnoreCase);              commands = Regex.Split(strScript, "GO\r\n", RegexOptions.IgnoreCase);
294              return commands;              return commands;
295          }          }
296            #endregion
297            #region public virtual bool RunScript(string strFile, out Exception ErrorInfo)
298          public virtual bool RunScript(string strFile, out Exception ErrorInfo)          public virtual bool RunScript(string strFile, out Exception ErrorInfo)
299          {          {
300              ErrorInfo = null;              ErrorInfo = null;
# Line 311  namespace AnywhereTS.DBSupport Line 340  namespace AnywhereTS.DBSupport
340              return false;              return false;
341          }          }
342          #endregion          #endregion
343            #endregion
344    
345          #region IDisposable Members          #region IDisposable Members
346          public virtual void Dispose()          public virtual void Dispose()

Legend:
Removed from v.87  
changed lines
  Added in v.116

  ViewVC Help
Powered by ViewVC 1.1.22