/[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

--- trunk/AnywhereTS.DBSupport/DBConnector.cs	2012/07/13 22:37:40	87
+++ trunk/AnywhereTS.DBSupport/DBConnector.cs	2012/07/13 22:56:50	89
@@ -24,7 +24,7 @@
         List<string> ExecuteColumnNamesReader(string command, List<DBParameter> Params, out Exception ErrorInfo);
 
         DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo);
-        public bool RunScript(string strFile, MsSqlConnector con, out Exception ErrorInfo);
+        bool RunScript(string strFile, out Exception ErrorInfo);
     }
     public abstract class DBConnector<DBParameter, DBCommand, DBConnection, DBDataAdapter> :
         IDBConnector<DBParameter, DBCommand, DBConnection, DBDataAdapter>
@@ -34,20 +34,32 @@
         where DBDataAdapter : DbDataAdapter, new()
     {
 
-        public DBConnector(string DBServerAddress, string DBServerInstance, string DBDatabase)
+        public DBConnector(string Address, string Instance, string Database)
         {
-            this.DBServerAddress = DBServerAddress;
-            this.DBServerInstance = DBServerInstance;
-            this.DBDatabase = DBDatabase;
+            DBServerAddress = Address;
+            DBServerInstance = Instance;
+            DBDatabase = Database;
         }
 
+        public static string GetConnectionString()
+        {
+            return string.Format(@"Data Source={0}\{1};Initial Catalog={2};Integrated Security=SSPI", DBServerAddress, DBServerInstance, DBDatabase);
+        }
         protected DBConnection connection;
-        protected string DBServerAddress = "";
-        protected string DBServerInstance = "";
-        protected string DBDatabase = "";
+        #region DBServerAddress, DBServerInstance, DBDatabase
+        internal static string DBServerAddress = "";
+        internal static string DBServerInstance = "";
+        internal static string DBDatabase = "";
+        #endregion
+        #region  private string SafeSqlLiteral(string inputSQL)
         private string SafeSqlLiteral(string inputSQL) { return inputSQL.Replace("'", "''"); }
+        #endregion
         #region IDBConnector members
-        public DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo)
+        #region  public virtual bool ConnectionIsOpen
+        public virtual bool ConnectionIsOpen { get; protected set; }
+        #endregion
+        #region public virtual DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo)
+        public virtual DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo)
         {
             ErrorInfo = null;
             try
@@ -74,17 +86,17 @@
                     Logging.DatabaseLog.Error(string.Format("Failed to create command instance using command: {0}", command));
                 }
                 ErrorInfo = ex; throw ErrorInfo;
-            } 
+            }
         }
-        private bool _ConnectionIsOpen;
-        public virtual bool ConnectionIsOpen { get { return _ConnectionIsOpen; } protected set { _ConnectionIsOpen = value; } }
+        #endregion
+        #region  public virtual void CreateConnection(out Exception ErrorInfo)
         public virtual void CreateConnection(out Exception ErrorInfo)
         {
             ErrorInfo = null;
             try
             {
                 string connetionString = null;
-                connetionString = string.Format(@"Data Source={0}\{1};Initial Catalog={2};Integrated Security=SSPI", DBServerAddress, DBServerInstance, DBDatabase);
+                connetionString = GetConnectionString();
                 connection = new DBConnection();
                 connection.ConnectionString = connetionString;
             }
@@ -103,8 +115,10 @@
                     Logging.DatabaseLog.Error(string.Format("Failed to create connection to {0} Database", DBDatabase));
                 }
                 ErrorInfo = ex; throw ErrorInfo;
-            } 
+            }
         }
+        #endregion
+        #region public virtual void OpenConnection(out Exception ErrorInfo)
         public virtual void OpenConnection(out Exception ErrorInfo)
         {
             ErrorInfo = null;
@@ -130,8 +144,10 @@
                     Logging.DatabaseLog.Error(string.Format("Failed to open connection to {0} Database", DBDatabase));
                 }
                 ErrorInfo = ex; throw ErrorInfo;
-            } 
+            }
         }
+        #endregion
+        #region public virtual void CloseConnection(out Exception ErrorInfo)
         public virtual void CloseConnection(out Exception ErrorInfo)
         {
             ErrorInfo = null;
@@ -155,9 +171,10 @@
                     Logging.DatabaseLog.Error(string.Format("Failed to close connection to {0} Database", DBDatabase));
                 }
                 ErrorInfo = ex; throw ErrorInfo;
-            } 
+            }
         }
-
+        #endregion
+        #region public virtual DbDataReader ExecuteQuery(string command, List<DBParameter> Params, out Exception ErrorInfo)
         public virtual DbDataReader ExecuteQuery(string command, List<DBParameter> Params, out Exception ErrorInfo)
         {
             ErrorInfo = null;
@@ -187,8 +204,10 @@
                     Logging.DatabaseLog.Error(string.Format("Failed to execute querey: {0}", command));
                 }
                 ErrorInfo = ex; throw ErrorInfo;
-            } 
+            }
         }
+        #endregion
+        #region public virtual void ExecuteNonQuery(string command, List<DBParameter> Params, out Exception ErrorInfo)
         public virtual void ExecuteNonQuery(string command, List<DBParameter> Params, out Exception ErrorInfo)
         {
             ErrorInfo = null;
@@ -217,8 +236,10 @@
                     Logging.DatabaseLog.Error(string.Format("Failed to execute non querey: {0}", command));
                 }
                 ErrorInfo = ex; throw ErrorInfo;
-            }    
+            }
         }
+        #endregion
+        #region 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)
         {
             ErrorInfo = null;
@@ -258,14 +279,18 @@
                     Logging.DatabaseLog.Error(string.Format("Failed to get colum names from reader: {0}", command));
                 }
                 ErrorInfo = ex; throw ErrorInfo;
-            }            
+            }
         }
+        #endregion
+        #region public string[] ParseScriptToCommands(string strScript)
         public string[] ParseScriptToCommands(string strScript)
         {
             string[] commands;
             commands = Regex.Split(strScript, "GO\r\n", RegexOptions.IgnoreCase);
             return commands;
         }
+        #endregion
+        #region public virtual bool RunScript(string strFile, out Exception ErrorInfo)
         public virtual bool RunScript(string strFile, out Exception ErrorInfo)
         {
             ErrorInfo = null;
@@ -311,6 +336,7 @@
             return false;
         }
         #endregion
+        #endregion
 
         #region IDisposable Members
         public virtual void Dispose()

 

  ViewVC Help
Powered by ViewVC 1.1.22