-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqlServerDataProvider.cs
More file actions
56 lines (47 loc) · 1.5 KB
/
Copy pathSqlServerDataProvider.cs
File metadata and controls
56 lines (47 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using DataKit.SQL.Providers;
using System.Data.SqlClient;
using System.Threading;
using System.Threading.Tasks;
namespace DataKit.SQL.SqlServer
{
public class SqlServerDataProvider : DataProviderBase
{
public const string PROVIDER_NAME = "Microsoft SQL Server";
public static SqlServerDataProvider Create(string host, string user, string pass, string database)
{
return new SqlServerDataProvider(new SqlConnectionStringBuilder
{
DataSource = host,
UserID = user,
Password = pass,
InitialCatalog = database
});
}
public override string ProviderName => PROVIDER_NAME;
private readonly string _connectionString;
public SqlServerDataProvider(string connectionString)
{
_connectionString = connectionString;
}
public SqlServerDataProvider(SqlConnectionStringBuilder connectionStringBuilder) :
this(connectionStringBuilder.ConnectionString)
{
}
protected override QueryWriter CreateQueryWriter()
{
return new SqlServerQueryWriter();
}
protected override IConnectionLease OpenConnection()
{
var connection = new SqlConnection(_connectionString);
connection.Open();
return new ClosingConnectionLease(connection);
}
protected override async Task<IConnectionLease> OpenConnectionAsync(CancellationToken cancellationToken)
{
var connection = new SqlConnection(_connectionString);
await connection.OpenAsync(cancellationToken);
return new ClosingConnectionLease(connection);
}
}
}