/[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/14 13:01:52	128
+++ trunk/AnywhereTS.DBSupport/DBConnector.cs	2012/07/15 02:55:20	131
@@ -17,7 +17,7 @@
         where DBDataAdapter : DbDataAdapter, new()
     {
         bool ConnectionIsOpen { get; }
-        void CreateConnection(out Exception ErrorInfo);
+        DBConnection CreateConnection(out Exception ErrorInfo);
         void OpenConnection(out Exception ErrorInfo);
         void CloseConnection(out Exception ErrorInfo);
 
@@ -25,7 +25,7 @@
         void ExecuteNonQuery(string command, List<DBParameter> Params, out Exception ErrorInfo);
         List<string> ExecuteColumnNamesReader(string command, List<DBParameter> Params, out Exception ErrorInfo);
 
-        DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo);
+        //DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo);
         bool RunScript(string strFile, out Exception ErrorInfo);
     }
     public abstract class DBConnector<DBParameter, DBCommand, DBConnection, DBDataAdapter> :
@@ -65,40 +65,40 @@
         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
-            {
-                command = this.SafeSqlLiteral(command);
-                DBCommand sqlComm = new DBCommand();
-                sqlComm.CommandText = command;
-                sqlComm.Connection = connection;
-                foreach (DBParameter p in Params) { sqlComm.Parameters.Add(p); }
-                return sqlComm;
-            }
-            catch (SqlException ex)
-            {
-                SqlException e = (ex.GetBaseException() as SqlException);
-                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())))
-                {
-                    Logging.DatabaseLog.Error(string.Format("Failed to create command instance using command: {0}", command));
-                }
-                ErrorInfo = ex; throw ErrorInfo;
-            }
-            catch (Exception ex)
-            {
-                Exception e = ex.GetBaseException();
-                using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", e.GetType().Name, e.Message, System.Environment.NewLine, e.ToString())))
-                {
-                    Logging.DatabaseLog.Error(string.Format("Failed to create command instance using command: {0}", command));
-                }
-                ErrorInfo = ex; throw ErrorInfo;
-            }
-        }
+        //public virtual DBCommand CreateCommandInstance(string command, List<DBParameter> Params, out Exception ErrorInfo)
+        //{
+        //    ErrorInfo = null;
+        //    try
+        //    {
+        //        command = this.SafeSqlLiteral(command);
+        //        DBCommand sqlComm = new DBCommand();
+        //        sqlComm.CommandText = command;
+        //        sqlComm.Connection = connection;
+        //        foreach (DBParameter p in Params) { sqlComm.Parameters.Add(p); }
+        //        return sqlComm;
+        //    }
+        //    catch (SqlException ex)
+        //    {
+        //        SqlException e = (ex.GetBaseException() as SqlException);
+        //        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())))
+        //        {
+        //            Logging.DatabaseLog.Error(string.Format("Failed to create command instance using command: {0}", command));
+        //        }
+        //        ErrorInfo = ex; throw ErrorInfo;
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        Exception e = ex.GetBaseException();
+        //        using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", e.GetType().Name, e.Message, System.Environment.NewLine, e.ToString())))
+        //        {
+        //            Logging.DatabaseLog.Error(string.Format("Failed to create command instance using command: {0}", command));
+        //        }
+        //        ErrorInfo = ex; throw ErrorInfo;
+        //    }
+        //}
         #endregion
-        #region  public virtual void CreateConnection(out Exception ErrorInfo)
-        public virtual void CreateConnection(out Exception ErrorInfo)
+        #region  public virtual DBConnection CreateConnection(out Exception ErrorInfo)
+        public virtual DBConnection CreateConnection(out Exception ErrorInfo)
         {
             ErrorInfo = null;
             string connetionString = string.Empty;
@@ -112,6 +112,7 @@
                     connection.ConnectionString = connetionString;
                     Logging.DatabaseLog.Debug("Created Connection");
                 }
+                return this.connection;
             }
             catch (SqlException ex)
             {
@@ -356,7 +357,8 @@
             try
             {
                 Exception ErrorInfo;
-                CloseConnection(out ErrorInfo);
+                if (this.ConnectionIsOpen)
+                    CloseConnection(out ErrorInfo);
             }
             catch
             {

 

  ViewVC Help
Powered by ViewVC 1.1.22