/[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 89 by william, Fri Jul 13 22:56:50 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 Address, string Instance, string Database)
38          {          {
39              this.DBServerAddress = DBServerAddress;              DBServerAddress = Address;
40              this.DBServerInstance = DBServerInstance;              DBServerInstance = Instance;
41              this.DBDatabase = DBDatabase;              DBDatabase = Database;
42          }          }
43    
44            public static string GetConnectionString()
45            {
46                return string.Format(@"Data Source={0}\{1};Initial Catalog={2};Integrated Security=SSPI", DBServerAddress, DBServerInstance, DBDatabase);
47            }
48          protected DBConnection connection;          protected DBConnection connection;
49          protected string DBServerAddress = "";          #region DBServerAddress, DBServerInstance, DBDatabase
50          protected string DBServerInstance = "";          internal static string DBServerAddress = "";
51          protected string DBDatabase = "";          internal static string DBServerInstance = "";
52            internal static string DBDatabase = "";
53            #endregion
54            #region  private string SafeSqlLiteral(string inputSQL)
55          private string SafeSqlLiteral(string inputSQL) { return inputSQL.Replace("'", "''"); }          private string SafeSqlLiteral(string inputSQL) { return inputSQL.Replace("'", "''"); }
56            #endregion
57          #region IDBConnector members          #region IDBConnector members
58          public DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo)          #region  public virtual bool ConnectionIsOpen
59            public virtual bool ConnectionIsOpen { get; protected set; }
60            #endregion
61            #region public virtual DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo)
62            public virtual DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo)
63          {          {
64              ErrorInfo = null;              ErrorInfo = null;
65              try              try
# Line 74  namespace AnywhereTS.DBSupport Line 86  namespace AnywhereTS.DBSupport
86                      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));
87                  }                  }
88                  ErrorInfo = ex; throw ErrorInfo;                  ErrorInfo = ex; throw ErrorInfo;
89              }              }
90          }          }
91          private bool _ConnectionIsOpen;          #endregion
92          public virtual bool ConnectionIsOpen { get { return _ConnectionIsOpen; } protected set { _ConnectionIsOpen = value; } }          #region  public virtual void CreateConnection(out Exception ErrorInfo)
93          public virtual void CreateConnection(out Exception ErrorInfo)          public virtual void CreateConnection(out Exception ErrorInfo)
94          {          {
95              ErrorInfo = null;              ErrorInfo = null;
96              try              try
97              {              {
98                  string connetionString = null;                  string connetionString = null;
99                  connetionString = string.Format(@"Data Source={0}\{1};Initial Catalog={2};Integrated Security=SSPI", DBServerAddress, DBServerInstance, DBDatabase);                  connetionString = GetConnectionString();
100                  connection = new DBConnection();                  connection = new DBConnection();
101                  connection.ConnectionString = connetionString;                  connection.ConnectionString = connetionString;
102              }              }
# Line 103  namespace AnywhereTS.DBSupport Line 115  namespace AnywhereTS.DBSupport
115                      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));
116                  }                  }
117                  ErrorInfo = ex; throw ErrorInfo;                  ErrorInfo = ex; throw ErrorInfo;
118              }              }
119          }          }
120            #endregion
121            #region public virtual void OpenConnection(out Exception ErrorInfo)
122          public virtual void OpenConnection(out Exception ErrorInfo)          public virtual void OpenConnection(out Exception ErrorInfo)
123          {          {
124              ErrorInfo = null;              ErrorInfo = null;
# Line 130  namespace AnywhereTS.DBSupport Line 144  namespace AnywhereTS.DBSupport
144                      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));
145                  }                  }
146                  ErrorInfo = ex; throw ErrorInfo;                  ErrorInfo = ex; throw ErrorInfo;
147              }              }
148          }          }
149            #endregion
150            #region public virtual void CloseConnection(out Exception ErrorInfo)
151          public virtual void CloseConnection(out Exception ErrorInfo)          public virtual void CloseConnection(out Exception ErrorInfo)
152          {          {
153              ErrorInfo = null;              ErrorInfo = null;
# Line 155  namespace AnywhereTS.DBSupport Line 171  namespace AnywhereTS.DBSupport
171                      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));
172                  }                  }
173                  ErrorInfo = ex; throw ErrorInfo;                  ErrorInfo = ex; throw ErrorInfo;
174              }              }
175          }          }
176            #endregion
177            #region public virtual DbDataReader ExecuteQuery(string command, List<DBParameter> Params, out Exception ErrorInfo)
178          public virtual DbDataReader ExecuteQuery(string command, List<DBParameter> Params, out Exception ErrorInfo)          public virtual DbDataReader ExecuteQuery(string command, List<DBParameter> Params, out Exception ErrorInfo)
179          {          {
180              ErrorInfo = null;              ErrorInfo = null;
# Line 187  namespace AnywhereTS.DBSupport Line 204  namespace AnywhereTS.DBSupport
204                      Logging.DatabaseLog.Error(string.Format("Failed to execute querey: {0}", command));                      Logging.DatabaseLog.Error(string.Format("Failed to execute querey: {0}", command));
205                  }                  }
206                  ErrorInfo = ex; throw ErrorInfo;                  ErrorInfo = ex; throw ErrorInfo;
207              }              }
208          }          }
209            #endregion
210            #region public virtual void ExecuteNonQuery(string command, List<DBParameter> Params, out Exception ErrorInfo)
211          public virtual void ExecuteNonQuery(string command, List<DBParameter> Params, out Exception ErrorInfo)          public virtual void ExecuteNonQuery(string command, List<DBParameter> Params, out Exception ErrorInfo)
212          {          {
213              ErrorInfo = null;              ErrorInfo = null;
# Line 217  namespace AnywhereTS.DBSupport Line 236  namespace AnywhereTS.DBSupport
236                      Logging.DatabaseLog.Error(string.Format("Failed to execute non querey: {0}", command));                      Logging.DatabaseLog.Error(string.Format("Failed to execute non querey: {0}", command));
237                  }                  }
238                  ErrorInfo = ex; throw ErrorInfo;                  ErrorInfo = ex; throw ErrorInfo;
239              }                  }
240          }          }
241            #endregion
242            #region public virtual List<string> ExecuteColumnNamesReader(string command, List<DBParameter> Params, out Exception ErrorInfo)
243          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)
244          {          {
245              ErrorInfo = null;              ErrorInfo = null;
# Line 258  namespace AnywhereTS.DBSupport Line 279  namespace AnywhereTS.DBSupport
279                      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));
280                  }                  }
281                  ErrorInfo = ex; throw ErrorInfo;                  ErrorInfo = ex; throw ErrorInfo;
282              }                          }
283          }          }
284            #endregion
285            #region public string[] ParseScriptToCommands(string strScript)
286          public string[] ParseScriptToCommands(string strScript)          public string[] ParseScriptToCommands(string strScript)
287          {          {
288              string[] commands;              string[] commands;
289              commands = Regex.Split(strScript, "GO\r\n", RegexOptions.IgnoreCase);              commands = Regex.Split(strScript, "GO\r\n", RegexOptions.IgnoreCase);
290              return commands;              return commands;
291          }          }
292            #endregion
293            #region public virtual bool RunScript(string strFile, out Exception ErrorInfo)
294          public virtual bool RunScript(string strFile, out Exception ErrorInfo)          public virtual bool RunScript(string strFile, out Exception ErrorInfo)
295          {          {
296              ErrorInfo = null;              ErrorInfo = null;
# Line 311  namespace AnywhereTS.DBSupport Line 336  namespace AnywhereTS.DBSupport
336              return false;              return false;
337          }          }
338          #endregion          #endregion
339            #endregion
340    
341          #region IDisposable Members          #region IDisposable Members
342          public virtual void Dispose()          public virtual void Dispose()

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

  ViewVC Help
Powered by ViewVC 1.1.22