/[AnywhereTS-MSSQL]/trunk/AnywhereTS.DBSupport/SqlMdfConnector.cs
ViewVC logotype

Diff of /trunk/AnywhereTS.DBSupport/SqlMdfConnector.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/AnywhereTS.DBSupport/SqlMdfConnector.cs	2012/07/13 22:56:50	89
+++ trunk/AnywhereTS.DBSupport/SqlMdfConnector.cs	2012/07/15 05:13:20	134
@@ -2,7 +2,8 @@
 using System.Collections.Generic;
 using System.Text;
 using System.Data.SqlClient;
-
+using System.Linq;
+using System.Text.RegularExpressions;
 namespace AnywhereTS.DBSupport
 {
     public class SqlMdfConnector : DBConnector<SqlParameter, SqlCommand, SqlConnection, SqlDataAdapter>
@@ -14,10 +15,14 @@
             ErrorInfo = null;
             try
             {
-                string connetionString = null;
-                connetionString = GetConnectionString();
-                connection = new SqlConnection();
-                connection.ConnectionString = connetionString;
+                string connetionString = GetConnectionString();
+                using (log4net.NDC.Push(string.Format("connetionString={0}", connetionString)))
+                {
+                    Logging.DatabaseLog.Debug("Creating Connection");
+                    connection = new SqlConnection();
+                    connection.ConnectionString = connetionString;
+                    Logging.DatabaseLog.Debug("Created Connection");
+                }
             }
             //catch (SqlException ex) { Console.WriteLine(ex.ToString()); ErrorInfo = ex;  throw ErrorInfo;}
             catch (Exception ex) { Console.WriteLine(ex.ToString()); ErrorInfo = ex; throw ErrorInfo; }
@@ -25,7 +30,33 @@
 
         new public static string GetConnectionString()
         {
-            return string.Format(@"Data Source={0}\{1};;AttachDbFilename=|DataDirectory|\{2};Integrated Security=SSPI", DBServerAddress, DBServerInstance, DBDatabase);
+            return string.Format(@"Data Source={0}\{1};AttachDbFilename=|DataDirectory|\{2};Integrated Security=SSPI", DBServerAddress, DBServerInstance, DBDatabase);
+        }
+
+        protected override bool ClientRunScript(string strFile, out Exception ErrorInfo)
+        {
+            ErrorInfo = null;
+            try
+            {
+                var commands = Regex.Split(strFile, string.Format(@"^GO{0}", System.Environment.NewLine), RegexOptions.IgnoreCase | RegexOptions.Multiline);
+                foreach (var command in commands)
+                {
+                    Logging.DatabaseLog.DebugFormat("Current Command={0}", command);
+                    SqlConnection sqlCon;
+                    this.GetConnectionClone(out sqlCon, out ErrorInfo);
+                    SqlCommand sqlcmd = new SqlCommand(command, this.connection);
+                    sqlcmd.CommandText = command;
+                    sqlcmd.Connection = sqlCon;
+                    sqlcmd.CommandType = System.Data.CommandType.Text;
+                    sqlcmd.ExecuteNonQuery();
+                }
+                return true;
+            }
+            catch (Exception ex)
+            {
+                ErrorInfo = ex;
+                throw ErrorInfo;
+            }
         }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22