/[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:56:50	89
+++ trunk/AnywhereTS.DBSupport/DBConnector.cs	2012/07/14 09:08:55	119
@@ -34,16 +34,20 @@
         where DBDataAdapter : DbDataAdapter, new()
     {
 
-        public DBConnector(string Address, string Instance, string Database)
+        public DBConnector(string Server, string Instance, string Database)
         {
-            DBServerAddress = Address;
+            DBServerAddress = Server;
             DBServerInstance = Instance;
             DBDatabase = Database;
+            using (log4net.NDC.Push(string.Format("[Server={0}] [Instance={1}] [Database={2}]", Server, Instance, Database)))
+            {
+                Logging.DatabaseLog.Debug("Creating DBConnector instance");
+            }
         }
 
         public static string GetConnectionString()
         {
-            return string.Format(@"Data Source={0}\{1};Initial Catalog={2};Integrated Security=SSPI", DBServerAddress, DBServerInstance, DBDatabase);
+            return string.Format(@"Data Source={0}\{1};Database={2};Integrated Security=SSPI", DBServerAddress, DBServerInstance, DBDatabase);
         }
         protected DBConnection connection;
         #region DBServerAddress, DBServerInstance, DBDatabase
@@ -286,12 +290,12 @@
         public string[] ParseScriptToCommands(string strScript)
         {
             string[] commands;
-            commands = Regex.Split(strScript, "GO\r\n", RegexOptions.IgnoreCase);
+            commands = strScript.Split(new string[] { string.Format("GO{0}", System.Environment.NewLine) }, StringSplitOptions.RemoveEmptyEntries);
             return commands;
         }
         #endregion
         #region public virtual bool RunScript(string strFile, out Exception ErrorInfo)
-        public virtual bool RunScript(string strFile, out Exception ErrorInfo)
+        public bool RunScript(string strFile, out Exception ErrorInfo)
         {
             ErrorInfo = null;
             try
@@ -300,20 +304,14 @@
                 strCommands = ParseScriptToCommands(strFile);
                 if (this.ConnectionIsOpen)
                 {
-                    foreach (string strCmd in strCommands)
+                    if (!ClientRunScript(strCommands, out ErrorInfo))
                     {
-                        if (strCmd.Length > 0)
-                        {
-                            // Substitute database directory with the decided one.
-                            DBCommand command = this.CreateCommandInstance(strCmd, new List<DBParameter>(), out ErrorInfo);
-                            command.ExecuteNonQuery();
-                        }
+                        return false;
                     }
-                    return true;
                 }
                 else
                 {
-                    Logging.ATSAdminLog.Fatal(string.Format("Failed to run script: [database connection is not open] {0}{1}", System.Environment.NewLine, strFile));
+                    Logging.DatabaseLog.Fatal(string.Format("Failed to run script: [database connection is not open] {0}{1}", System.Environment.NewLine, strFile));
                     return false;
                 }
             }
@@ -335,6 +333,7 @@
             }
             return false;
         }
+        public abstract bool ClientRunScript(string[] strCommands, out Exception ErrorInfo);
         #endregion
         #endregion
 

 

  ViewVC Help
Powered by ViewVC 1.1.22