ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/AnywhereTS-MSSQL/trunk/AnywhereTS.DBSupport/MSSQLConnector.cs
Revision: 128
Committed: Sat Jul 14 13:01:52 2012 UTC (11 years, 2 months ago) by william
File size: 1396 byte(s)
Log Message:
+ fix RunScript ==> CommandType must be set to Text

File Contents

# Content
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Data.SqlClient;
5 using System.Linq;
6 using System.Text.RegularExpressions;
7 namespace AnywhereTS.DBSupport
8 {
9 public class MsSqlConnector : DBConnector<SqlParameter,SqlCommand,SqlConnection,SqlDataAdapter>
10 {
11 public MsSqlConnector(string DBServerAddress, string DBServerInstance, string DBDatabase) : base(DBServerAddress, DBServerInstance, DBDatabase) { }
12
13
14 protected override bool ClientRunScript(string strFile, out Exception ErrorInfo)
15 {
16 ErrorInfo = null;
17 try
18 {
19 var commands = Regex.Split(strFile, string.Format(@"^GO${0}", System.Environment.NewLine), RegexOptions.IgnoreCase | RegexOptions.Multiline);
20 foreach (var command in commands)
21 {
22 SqlCommand sqlcmd = this.CreateCommandInstance(command, new List<SqlParameter>(), out ErrorInfo);
23 sqlcmd.CommandType = System.Data.CommandType.Text;
24 if (ErrorInfo != null)
25 throw ErrorInfo;
26 sqlcmd.ExecuteNonQuery();
27 }
28 return true;
29 }
30 catch (Exception ex)
31 {
32 ErrorInfo = ex;
33 return false;
34 }
35 }
36 }
37 }