forked from sergiisyrovatchenko/SQLIndexManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnection.cs
More file actions
33 lines (25 loc) · 919 Bytes
/
Copy pathConnection.cs
File metadata and controls
33 lines (25 loc) · 919 Bytes
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
using System.Data.SqlClient;
namespace SQLIndexManager {
public static class Connection {
private static string GetConnectionString(Host host, string database) {
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder() {
ApplicationName = Settings.ExeName,
ConnectTimeout = Settings.Options.ConnectionTimeout,
DataSource = host.Server,
InitialCatalog = database ?? "master"
};
if (host.AuthType == AuthTypes.Windows) {
builder.IntegratedSecurity = true;
}
else {
builder.UserID = host.User;
builder.Password = host.Password ?? string.Empty;
}
return builder.ConnectionString;
}
public static SqlConnection Create(Host host, string database = null) {
string connectionString = GetConnectionString(host, database);
return new SqlConnection(connectionString);
}
}
}