first commit
This commit is contained in:
47
Keps.WinForms/Infrastructure/SqlConnectionFactory.cs
Normal file
47
Keps.WinForms/Infrastructure/SqlConnectionFactory.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace Keps.WinForms.Infrastructure
|
||||
{
|
||||
public sealed class SqlConnectionFactory
|
||||
{
|
||||
private readonly string _connectionString;
|
||||
|
||||
/// <summary>
|
||||
/// 주어진 레거시 DB 연결 설정으로 <see cref="SqlConnection"/>을 생성하기 위한 팩토리를 초기화합니다.
|
||||
/// </summary>
|
||||
/// <param name="settings">서버, 데이터베이스, 사용자, 비밀번호 등의 연결 정보.</param>
|
||||
public SqlConnectionFactory(LegacyConnectionSettings settings)
|
||||
{
|
||||
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
|
||||
builder.DataSource = settings.Server;
|
||||
builder.InitialCatalog = settings.Database;
|
||||
builder.UserID = settings.UserId;
|
||||
builder.Password = settings.Password;
|
||||
builder.IntegratedSecurity = false;
|
||||
builder.ConnectTimeout = 30;
|
||||
builder.TrustServerCertificate = true;
|
||||
builder.Encrypt = false;
|
||||
|
||||
_connectionString = builder.ConnectionString;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 구성된 연결 문자열로 SQL Server 연결을 열어 반환합니다.
|
||||
/// </summary>
|
||||
/// <returns>열린 상태의 <see cref="SqlConnection"/>.</returns>
|
||||
public SqlConnection Open()
|
||||
{
|
||||
SqlConnection connection = new SqlConnection(_connectionString);
|
||||
connection.Open();
|
||||
return connection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 내부에서 사용되는 연결 문자열을 반환합니다.
|
||||
/// </summary>
|
||||
public string ConnectionString
|
||||
{
|
||||
get { return _connectionString; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user