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

revision 89 by william, Fri Jul 13 22:56:50 2012 UTC revision 131 by william, Sun Jul 15 02:55:20 2012 UTC
# Line 2  Line 2 
2  using System.Collections.Generic;  using System.Collections.Generic;
3  using System.Text;  using System.Text;
4  using System.Data.SqlClient;  using System.Data.SqlClient;
5    using System.Linq;
6    using System.Text.RegularExpressions;
7  namespace AnywhereTS.DBSupport  namespace AnywhereTS.DBSupport
8  {  {
9      public class SqlMdfConnector : DBConnector<SqlParameter, SqlCommand, SqlConnection, SqlDataAdapter>      public class SqlMdfConnector : DBConnector<SqlParameter, SqlCommand, SqlConnection, SqlDataAdapter>
10      {              {        
11          public SqlMdfConnector(string DBServerAddress, string DBServerInstance, string SqlMdf) : base(DBServerAddress, DBServerInstance, SqlMdf) { }          public SqlMdfConnector(string DBServerAddress, string DBServerInstance, string SqlMdf) : base(DBServerAddress, DBServerInstance, SqlMdf) { }
12    
13          public override void CreateConnection(out Exception ErrorInfo)          public override SqlConnection CreateConnection(out Exception ErrorInfo)
14          {          {
15              ErrorInfo = null;              ErrorInfo = null;
16              try              try
# Line 18  namespace AnywhereTS.DBSupport Line 19  namespace AnywhereTS.DBSupport
19                  connetionString = GetConnectionString();                  connetionString = GetConnectionString();
20                  connection = new SqlConnection();                  connection = new SqlConnection();
21                  connection.ConnectionString = connetionString;                  connection.ConnectionString = connetionString;
22                    return connection;
23              }              }
24              //catch (SqlException ex) { Console.WriteLine(ex.ToString()); ErrorInfo = ex;  throw ErrorInfo;}              //catch (SqlException ex) { Console.WriteLine(ex.ToString()); ErrorInfo = ex;  throw ErrorInfo;}
25              catch (Exception ex) { Console.WriteLine(ex.ToString()); ErrorInfo = ex; throw ErrorInfo; }              catch (Exception ex) { Console.WriteLine(ex.ToString()); ErrorInfo = ex; throw ErrorInfo; }
# Line 25  namespace AnywhereTS.DBSupport Line 27  namespace AnywhereTS.DBSupport
27    
28          new public static string GetConnectionString()          new public static string GetConnectionString()
29          {          {
30              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);
31            }
32    
33            protected override bool ClientRunScript(string strFile, out Exception ErrorInfo)
34            {
35                ErrorInfo = null;
36                try
37                {
38                    var commands = Regex.Split(strFile, string.Format(@"^GO{0}", System.Environment.NewLine), RegexOptions.IgnoreCase | RegexOptions.Multiline);
39                    foreach (var command in commands)
40                    {
41                        Logging.DatabaseLog.DebugFormat("Current Command={0}", command);
42                        SqlCommand sqlcmd = new SqlCommand(command, this.connection);
43                        sqlcmd.CommandType = System.Data.CommandType.Text;
44                        if (ErrorInfo != null)
45                            throw ErrorInfo;
46                        sqlcmd.ExecuteNonQuery();
47                    }
48                    return true;
49                }
50                catch (Exception ex)
51                {
52                    ErrorInfo = ex;
53                    return false;
54                }
55          }          }
56      }      }
57  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.22