Viewer to Server
This commit is contained in:
30
Server/Services/SQLDbConnectionFactory.cs
Normal file
30
Server/Services/SQLDbConnectionFactory.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using OI.Metrology.Server.Models;
|
||||
using OI.Metrology.Shared.Repositories;
|
||||
using System.Data.Common;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
#pragma warning disable CS8600, CS8602, CS8603, CS8604, CS8625
|
||||
|
||||
namespace OI.Metrology.Server.Services;
|
||||
|
||||
public class SQLDbConnectionFactory : IDbConnectionFactory
|
||||
{
|
||||
private readonly AppSettings _AppSettings;
|
||||
|
||||
public SQLDbConnectionFactory(AppSettings appSettings) => _AppSettings = appSettings;
|
||||
|
||||
public DbConnection GetDbConnection()
|
||||
{
|
||||
DbProviderFactories.RegisterFactory(
|
||||
typeof(SqlConnection).Namespace,
|
||||
SqlClientFactory.Instance);
|
||||
|
||||
if (string.IsNullOrEmpty(_AppSettings.ConnectionString))
|
||||
throw new Exception("Connection string is missing");
|
||||
|
||||
DbConnection c = SqlClientFactory.Instance.CreateConnection();
|
||||
c.ConnectionString = _AppSettings.ConnectionString;
|
||||
c.Open();
|
||||
return c;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user