/[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 125 - (hide annotations) (download)
Sat Jul 14 11:44:52 2012 UTC (9 years, 3 months ago) by william
File size: 2201 byte(s)
+ remove reference to  Sql Server SMO components
+ attempt to fix .sql script parsing to split on GO statements

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     public override void CreateConnection(out Exception ErrorInfo)
14     {
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     }
23     //catch (SqlException ex) { Console.WriteLine(ex.ToString()); ErrorInfo = ex; throw ErrorInfo;}
24     catch (Exception ex) { Console.WriteLine(ex.ToString()); ErrorInfo = ex; throw ErrorInfo; }
25     }
26 william 89
27     new public static string GetConnectionString()
28     {
29 william 119 return string.Format(@"Data Source={0}\{1};AttachDbFilename=|DataDirectory|\{2};Integrated Security=SSPI", DBServerAddress, DBServerInstance, DBDatabase);
30 william 89 }
31 william 119
32 william 123 protected override bool ClientRunScript(string strFile, out Exception ErrorInfo)
33 william 119 {
34     ErrorInfo = null;
35     try
36 william 125 {
37     var commands = Regex.Split(strFile, string.Format(@"^GO${0}", System.Environment.NewLine), RegexOptions.IgnoreCase | RegexOptions.Multiline);
38     foreach (var command in commands)
39     {
40     SqlCommand sqlcmd = this.CreateCommandInstance(command, new List<SqlParameter>(), out ErrorInfo);
41     if (ErrorInfo != null)
42     throw ErrorInfo;
43     sqlcmd.ExecuteNonQuery();
44     }
45 william 119 return true;
46     }
47     catch (Exception ex)
48     {
49     ErrorInfo = ex;
50     return false;
51     }
52     }
53 william 85 }
54     }

  ViewVC Help
Powered by ViewVC 1.1.22