/[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 123 - (hide annotations) (download)
Sat Jul 14 11:14:09 2012 UTC (8 years, 11 months ago) by william
File size: 1869 byte(s)
+ bulk commit
-- add SQLSerer SMO support for executing TSQL commands

1 william 85 using System;
2     using System.Collections.Generic;
3     using System.Text;
4     using System.Data.SqlClient;
5 william 123 using Microsoft.SqlServer.Management.Common;
6     using Microsoft.SqlServer.Management.Smo;
7 william 85
8     namespace AnywhereTS.DBSupport
9     {
10     public class SqlMdfConnector : DBConnector<SqlParameter, SqlCommand, SqlConnection, SqlDataAdapter>
11     {
12     public SqlMdfConnector(string DBServerAddress, string DBServerInstance, string SqlMdf) : base(DBServerAddress, DBServerInstance, SqlMdf) { }
13    
14     public override void CreateConnection(out Exception ErrorInfo)
15     {
16     ErrorInfo = null;
17     try
18     {
19     string connetionString = null;
20 william 89 connetionString = GetConnectionString();
21 william 85 connection = new SqlConnection();
22     connection.ConnectionString = connetionString;
23     }
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     {
38 william 123 Server server = new Server(new ServerConnection(this.connection));
39     server.ConnectionContext.ExecuteNonQuery(strFile);
40 william 119 return true;
41     }
42     catch (Exception ex)
43     {
44     ErrorInfo = ex;
45     return false;
46     }
47     }
48 william 85 }
49     }

  ViewVC Help
Powered by ViewVC 1.1.22