-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
87 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Microsoft.Data.SqlClient; | ||
using Microsoft.SqlServer.Management.Common; | ||
using Microsoft.SqlServer.Management.Smo; | ||
using System; | ||
|
||
namespace FIASUpdate | ||
{ | ||
internal abstract class DBClient : IDisposable | ||
{ | ||
protected readonly Database DB; | ||
protected readonly string DBName = FIASProperties.DBName; | ||
|
||
protected DBClient() | ||
{ | ||
SqlConnection Connection = NewConnection(); | ||
Server Server = new Server(new ServerConnection(Connection)); | ||
DB = Server.Databases[DBName]; | ||
if (DB == null) { throw new InvalidOperationException($"База данных {DBName} не найдена"); } | ||
DB.Refresh(); | ||
} | ||
|
||
protected static SqlConnection NewConnection() => NewConnection("master"); | ||
|
||
protected static SqlConnection NewConnection(string Database) | ||
{ | ||
var SCSB = new SqlConnectionStringBuilder(FIASProperties.SQLConnection) | ||
{ | ||
InitialCatalog = Database, | ||
Encrypt = false | ||
}; | ||
var connection = new SqlConnection(SCSB.ToString()); | ||
connection.Open(); | ||
return connection; | ||
} | ||
|
||
#region IDisposable | ||
private bool disposedValue; | ||
|
||
public void Dispose() => Dispose(true); | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (!disposedValue) | ||
{ | ||
if (disposing) | ||
{ | ||
DB.Parent.ConnectionContext.Disconnect(); | ||
} | ||
disposedValue = true; | ||
} | ||
} | ||
|
||
#endregion IDisposable | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters