|
|
@ -7,7 +7,7 @@ using System.Data.SqlClient;
|
|
|
|
namespace ZeroLevel.SqlServer
|
|
|
|
namespace ZeroLevel.SqlServer
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class DbReader
|
|
|
|
public class DbReader
|
|
|
|
:IDisposable
|
|
|
|
: IDisposable
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly DbConnection _connection;
|
|
|
|
private readonly DbConnection _connection;
|
|
|
|
private readonly IDbCommand _command;
|
|
|
|
private readonly IDbCommand _command;
|
|
|
@ -76,6 +76,7 @@ namespace ZeroLevel.SqlServer
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
connection.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -88,9 +89,16 @@ namespace ZeroLevel.SqlServer
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (DbConnection connection = _factory.CreateConnection())
|
|
|
|
using (DbConnection connection = _factory.CreateConnection())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var cmd = CreateCommand(connection, query, par, Timeout))
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var cmd = CreateCommand(connection, query, par, Timeout))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return cmd.ExecuteNonQuery();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return cmd.ExecuteNonQuery();
|
|
|
|
connection.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -108,6 +116,7 @@ namespace ZeroLevel.SqlServer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
connection.Close();
|
|
|
|
connection.Dispose();
|
|
|
|
connection.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -148,6 +157,7 @@ namespace ZeroLevel.SqlServer
|
|
|
|
da.Fill(ds);
|
|
|
|
da.Fill(ds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
connection.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ds;
|
|
|
|
return ds;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -164,6 +174,7 @@ namespace ZeroLevel.SqlServer
|
|
|
|
da.Fill(ds);
|
|
|
|
da.Fill(ds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
connection.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ds;
|
|
|
|
return ds;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -174,9 +185,16 @@ namespace ZeroLevel.SqlServer
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var connection = _factory.CreateConnection())
|
|
|
|
using (var connection = _factory.CreateConnection())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var cmd = CreateCommand(connection, query, null, Timeout))
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var cmd = CreateCommand(connection, query, null, Timeout))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return cmd.ExecuteScalar();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return cmd.ExecuteScalar();
|
|
|
|
connection.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -185,9 +203,16 @@ namespace ZeroLevel.SqlServer
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var connection = _factory.CreateConnection())
|
|
|
|
using (var connection = _factory.CreateConnection())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var cmd = CreateCommand(connection, query, par, Timeout))
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var cmd = CreateCommand(connection, query, par, Timeout))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return cmd.ExecuteScalar();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return cmd.ExecuteScalar();
|
|
|
|
connection.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -198,13 +223,20 @@ namespace ZeroLevel.SqlServer
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var connection = _factory.CreateConnection())
|
|
|
|
using (var connection = _factory.CreateConnection())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var command = new SqlCommand(name, connection)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CommandType = CommandType.StoredProcedure
|
|
|
|
using (var command = new SqlCommand(name, connection)
|
|
|
|
})
|
|
|
|
{
|
|
|
|
|
|
|
|
CommandType = CommandType.StoredProcedure
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
command.CommandTimeout = 300000;
|
|
|
|
|
|
|
|
return command.ExecuteNonQuery();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
{
|
|
|
|
command.CommandTimeout = 300000;
|
|
|
|
connection.Close();
|
|
|
|
return command.ExecuteNonQuery();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -281,7 +313,7 @@ namespace ZeroLevel.SqlServer
|
|
|
|
return new SqlParameter[0];
|
|
|
|
return new SqlParameter[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static SqlCommand CreateCommand(DbConnection connection, string query, DbParameter[] parameters, int timeout)
|
|
|
|
public static SqlCommand CreateCommand(DbConnection connection, string query, DbParameter[] parameters, int timeout)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var command = connection.CreateCommand();
|
|
|
|
var command = connection.CreateCommand();
|
|
|
|
command.CommandText = query;
|
|
|
|
command.CommandText = query;
|
|
|
|