ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/AnywhereTS-MSSQL/trunk/AnywhereTS.DBSupport/SqlMdfConnector.cs
Revision: 123
Committed: Sat Jul 14 11:14:09 2012 UTC (11 years, 4 months ago) by william
File size: 1869 byte(s)
Log Message:
+ bulk commit
-- add SQLSerer SMO support for executing TSQL commands

File Contents

# Content
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Data.SqlClient;
5 using Microsoft.SqlServer.Management.Common;
6 using Microsoft.SqlServer.Management.Smo;
7
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 connetionString = GetConnectionString();
21 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
28 new public static string GetConnectionString()
29 {
30 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 Server server = new Server(new ServerConnection(this.connection));
39 server.ConnectionContext.ExecuteNonQuery(strFile);
40 return true;
41 }
42 catch (Exception ex)
43 {
44 ErrorInfo = ex;
45 return false;
46 }
47 }
48 }
49 }