init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
182
Sda.DataProvider/Wrappers/MSSQL/MSSQLConnectionWrapper.cs
Normal file
182
Sda.DataProvider/Wrappers/MSSQL/MSSQLConnectionWrapper.cs
Normal file
|
@ -0,0 +1,182 @@
|
|||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using SDA.DataProvider.Core;
|
||||
using SDA.DataProvider.Wrappers.MSSQL;
|
||||
|
||||
namespace SDA.DataProvider.MSSQLWrappers
|
||||
{
|
||||
class MSSQLConnectionWrapper : SDAConnectionWrapper
|
||||
{
|
||||
internal SqlConnection Connection;
|
||||
internal MSSQLConnectionStringBuilderWrapper ConnectionStringBuilder;
|
||||
|
||||
protected override IDbConnection WrappedConnection
|
||||
{
|
||||
get
|
||||
{
|
||||
return Connection;
|
||||
}
|
||||
}
|
||||
|
||||
public MSSQLConnectionWrapper()
|
||||
{
|
||||
Connection = new SqlConnection();
|
||||
}
|
||||
|
||||
public MSSQLConnectionWrapper(string connectionString)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConnectionStringBuilder = new MSSQLConnectionStringBuilderWrapper(connectionString);
|
||||
Connection = new SqlConnection(ConnectionStringBuilder.ConnectionString);
|
||||
}
|
||||
catch (SqlException exception)
|
||||
{
|
||||
throw MSSQLExceptionHelper.TranslateSqlException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
ConnectionStringBuilder.Dispose();
|
||||
Connection.Dispose();
|
||||
|
||||
ConnectionStringBuilder = null;
|
||||
Connection = null;
|
||||
}
|
||||
|
||||
public override void Open()
|
||||
{
|
||||
try
|
||||
{
|
||||
Connection.Open();
|
||||
}
|
||||
catch (SqlException exception)
|
||||
{
|
||||
throw MSSQLExceptionHelper.TranslateSqlException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SDABulkAdapter CreateBulkAdapter(SDATransaction transaction = null)
|
||||
{
|
||||
SqlBulkCopy sqlBulkCopy;
|
||||
|
||||
if (transaction == null)
|
||||
{
|
||||
sqlBulkCopy = new SqlBulkCopy(Connection);
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlBulkCopy = new SqlBulkCopy(Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction.NativeTransaction);
|
||||
}
|
||||
return new MSSQLBulkAdapter(sqlBulkCopy);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ResetConnectionPool(bool all = false)
|
||||
{
|
||||
if (all)
|
||||
{
|
||||
SqlConnection.ClearAllPools();
|
||||
}
|
||||
else
|
||||
{
|
||||
SqlConnection.ClearPool(Connection);
|
||||
}
|
||||
}
|
||||
|
||||
public override SDATransactionWrapper BeginTransaction()
|
||||
{
|
||||
try
|
||||
{
|
||||
return new MSSQLTransactionWrapper(this, Connection.BeginTransaction());
|
||||
}
|
||||
catch (SqlException exception)
|
||||
{
|
||||
throw MSSQLExceptionHelper.TranslateSqlException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
public override SDATransactionWrapper BeginTransaction(IsolationLevel isolationLevel)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new MSSQLTransactionWrapper(this, Connection.BeginTransaction(isolationLevel));
|
||||
}
|
||||
catch (SqlException exception)
|
||||
{
|
||||
throw MSSQLExceptionHelper.TranslateSqlException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
public override SDACommandWrapper CreateCommand()
|
||||
{
|
||||
MSSQLCommandWrapper result = null;
|
||||
try
|
||||
{
|
||||
// ReSharper disable once UseObjectOrCollectionInitializer
|
||||
result = new MSSQLCommandWrapper();
|
||||
result.Connection = this;
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (result != null)
|
||||
{
|
||||
result.Dispose();
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
return Connection.ConnectionString;
|
||||
}
|
||||
set
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ConnectionStringBuilder == null)
|
||||
{
|
||||
ConnectionStringBuilder = new MSSQLConnectionStringBuilderWrapper(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConnectionStringBuilder.ConnectionString = value;
|
||||
}
|
||||
|
||||
Connection.ConnectionString = ConnectionStringBuilder.ConnectionString;
|
||||
}
|
||||
catch (SqlException exception)
|
||||
{
|
||||
throw MSSQLExceptionHelper.TranslateSqlException(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override int ConnectionTimeout
|
||||
{
|
||||
get
|
||||
{
|
||||
return Connection.ConnectionTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ChangeDatabase(string databaseName)
|
||||
{
|
||||
try
|
||||
{
|
||||
Connection.ChangeDatabase(databaseName);
|
||||
}
|
||||
catch (SqlException exception)
|
||||
{
|
||||
throw MSSQLExceptionHelper.TranslateSqlException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue