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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 133 - (hide annotations) (download)
Sun Jul 15 05:00:59 2012 UTC (8 years, 11 months ago) by william
File size: 2549 byte(s)
+ wip to get rid of errors

1 william 85 using System;
2     using System.Collections.Generic;
3     using System.Text;
4     using System.Data.SqlClient;
5 william 125 using System.Linq;
6     using System.Text.RegularExpressions;
7 william 85 namespace AnywhereTS.DBSupport
8     {
9     public class SqlMdfConnector : DBConnector<SqlParameter, SqlCommand, SqlConnection, SqlDataAdapter>
10     {
11     public SqlMdfConnector(string DBServerAddress, string DBServerInstance, string SqlMdf) : base(DBServerAddress, DBServerInstance, SqlMdf) { }
12    
13 william 133 public override void CreateConnection(out Exception ErrorInfo)
14 william 85 {
15     ErrorInfo = null;
16     try
17     {
18 william 133 string connetionString = GetConnectionString();
19     using (log4net.NDC.Push(string.Format("connetionString={0}", connetionString)))
20     {
21     Logging.DatabaseLog.Debug("Creating Connection");
22     connection = new SqlConnection();
23     connection.ConnectionString = connetionString;
24     Logging.DatabaseLog.Debug("Created Connection");
25     }
26 william 85 }
27     //catch (SqlException ex) { Console.WriteLine(ex.ToString()); ErrorInfo = ex; throw ErrorInfo;}
28     catch (Exception ex) { Console.WriteLine(ex.ToString()); ErrorInfo = ex; throw ErrorInfo; }
29     }
30 william 89
31     new public static string GetConnectionString()
32     {
33 william 119 return string.Format(@"Data Source={0}\{1};AttachDbFilename=|DataDirectory|\{2};Integrated Security=SSPI", DBServerAddress, DBServerInstance, DBDatabase);
34 william 89 }
35 william 119
36 william 123 protected override bool ClientRunScript(string strFile, out Exception ErrorInfo)
37 william 119 {
38     ErrorInfo = null;
39     try
40 william 128 {
41 william 129 var commands = Regex.Split(strFile, string.Format(@"^GO{0}", System.Environment.NewLine), RegexOptions.IgnoreCase | RegexOptions.Multiline);
42 william 125 foreach (var command in commands)
43     {
44 william 129 Logging.DatabaseLog.DebugFormat("Current Command={0}", command);
45 william 130 SqlCommand sqlcmd = new SqlCommand(command, this.connection);
46 william 128 sqlcmd.CommandType = System.Data.CommandType.Text;
47 william 125 if (ErrorInfo != null)
48     throw ErrorInfo;
49     sqlcmd.ExecuteNonQuery();
50     }
51 william 119 return true;
52     }
53     catch (Exception ex)
54     {
55     ErrorInfo = ex;
56     return false;
57     }
58     }
59 william 85 }
60     }

  ViewVC Help
Powered by ViewVC 1.1.22