/[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 131 - (hide annotations) (download)
Sun Jul 15 02:55:20 2012 UTC (8 years, 11 months ago) by william
File size: 2351 byte(s)
+ move all database options to DatabaseLog (even if it comes from ATSAdmin.exe)

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 131 public override SqlConnection CreateConnection(out Exception ErrorInfo)
14 william 85 {
15     ErrorInfo = null;
16     try
17     {
18     string connetionString = null;
19 william 89 connetionString = GetConnectionString();
20 william 85 connection = new SqlConnection();
21     connection.ConnectionString = connetionString;
22 william 131 return connection;
23 william 85 }
24     //catch (SqlException ex) { Console.WriteLine(ex.ToString()); ErrorInfo = ex; throw ErrorInfo;}
25     catch (Exception ex) { Console.WriteLine(ex.ToString()); ErrorInfo = ex; throw ErrorInfo; }
26     }
27 william 89
28     new public static string GetConnectionString()
29     {
30 william 119 return string.Format(@"Data Source={0}\{1};AttachDbFilename=|DataDirectory|\{2};Integrated Security=SSPI", DBServerAddress, DBServerInstance, DBDatabase);
31 william 89 }
32 william 119
33 william 123 protected override bool ClientRunScript(string strFile, out Exception ErrorInfo)
34 william 119 {
35     ErrorInfo = null;
36     try
37 william 128 {
38 william 129 var commands = Regex.Split(strFile, string.Format(@"^GO{0}", System.Environment.NewLine), RegexOptions.IgnoreCase | RegexOptions.Multiline);
39 william 125 foreach (var command in commands)
40     {
41 william 129 Logging.DatabaseLog.DebugFormat("Current Command={0}", command);
42 william 130 SqlCommand sqlcmd = new SqlCommand(command, this.connection);
43 william 128 sqlcmd.CommandType = System.Data.CommandType.Text;
44 william 125 if (ErrorInfo != null)
45     throw ErrorInfo;
46     sqlcmd.ExecuteNonQuery();
47     }
48 william 119 return true;
49     }
50     catch (Exception ex)
51     {
52     ErrorInfo = ex;
53     return false;
54     }
55     }
56 william 85 }
57     }

  ViewVC Help
Powered by ViewVC 1.1.22