本文整理汇总了C#中IDbTransaction类的典型用法代码示例。如果您正苦于以下问题:C# IDbTransaction类的具体用法?C# IDbTransaction怎么用?C# IDbTransaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IDbTransaction类属于命名空间,在下文中一共展示了IDbTransaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateCommand
public IDbCommand CreateCommand(string cmdText, IDbConnection connection, IDbTransaction transaction)
{
IDbCommand cmd = connection.CreateCommand();
cmd.CommandText = cmdText;
cmd.Transaction = transaction;
return cmd;
}
示例2: ConvertQualityModels
private void ConvertQualityModels(IDbConnection conn, IDbTransaction tran)
{
// Converts the QualityModel JSON objects to their new format (only storing the QualityId instead of the entire object)
ConvertQualityModel(conn, tran, "Blacklist");
ConvertQualityModel(conn, tran, "EpisodeFiles");
ConvertQualityModel(conn, tran, "History");
}
示例3: RuntimeContext
public RuntimeContext(IDbConnection connection, IDbTransaction transaction, IDbCommandExecutor executor, IProviderMetadata providerMetadata, IMigrationStepMetadata stepMetadata)
: base(providerMetadata, stepMetadata)
{
_connection = connection;
_transaction = transaction;
_executor = executor;
}
示例4: AffectData
public static int AffectData(string TSQL, IDbConnection myConn, IDbTransaction myTrans, List<IDbDataParameter> myParams)
{
bool mustClose = false;
if (myConn == null)
{
mustClose = true;
myConn = clsConn.getConnOLE();
}
if (myConn.State != ConnectionState.Open)
myConn.Open();
OleDbCommand myCMD = new OleDbCommand();
//
myCMD.Connection = myConn as OleDbConnection;
if (myTrans != null)
myCMD.Transaction = myTrans as OleDbTransaction;
//
myCMD.CommandType = CommandType.Text;
myCMD.CommandText = TSQL;
myCMD.CommandTimeout = 180000;//3 phut
//
if (myParams != null)
AttachParameters(myCMD, myParams);
int CMDResult = myCMD.ExecuteNonQuery();
//
if (mustClose) myConn.Close();
return CMDResult;
}
示例5: CheckDeleteControl
/// <summary>
/// Проверить возможность удаления компонента
/// </summary>
/// <param name="request">бъект-оболочка RequestPackage, содержащая в поле requestID ID компонента</param>
/// <param name="connectionID">Объект подключения к базе данных</param>
/// <returns>Объект-оболочка ResponsePackagе</returns>
public ResponsePackage CheckDeleteControl(RequestPackage request, IDbConnection connectionID, IDbTransaction transactionID)
{
string sql = string.Format(
" select id from CONTROL_QUERY_MAPPING where control_id = {0} " +
" union " +
" select id from FORM_IN_PARAMETERS where control_id = {0} " +
" union " +
" select id from FORM_OUT_PARAMETERS where control_id = {0} " +
" union " +
" select id from ACTION_PARAMETERS where control_id = {0} " +
" union " +
" select id from QUERY_QUERY_IN_PARAMETER where control_id = {0} ",
request.requestID
);
ResponseTablePackage res = DBUtils.OpenSQL(sql, connectionID, transactionID);
res.ThrowExceptionIfError();
if (res.resultData.Rows.Count > 0)
{
return new ResponsePackage() { resultCode = -1, resultMessage = "Удаление компонента невозможно. Проверьте все ссылки на него." };
}
else
{
return new ResponsePackage() { resultCode = 0, resultMessage = "Удаление возможно." };
}
}
示例6: ExecuteWithTransaction
public void ExecuteWithTransaction(IDbConnection db, IDbTransaction transaction)
{
db.Execute(@"IF @EndPointType = 3
BEGIN
UPDATE dbo.Company SET QueueId = @QueueId
WHERE Company.CompanyId = @EndPointId
END
ELSE IF @EndPointType = 0
BEGIN
UPDATE dbo.Agent SET QueueId = @QueueId
WHERE Agent.AgentId = @EndPointId
END
ELSE IF @EndPointType = 1
BEGIN
UPDATE dbo.Team SET QueueId = @QueueId
WHERE Team.TeamId = @EndPointId
END
ELSE IF @EndPointType = 2
BEGIN
UPDATE dbo.Department SET QueueId = @QueueId
WHERE Department.DepartmentId = @EndPointId
END",
new
{
EndPointType = _endPoint.EndPointType,
EndPointId = _endPoint.EndpointId,
QueueId = _endPoint.QueueId
}, transaction);
}
示例7: SqlServerFetchedJob
public SqlServerFetchedJob(
[NotNull] SqlServerStorage storage,
[NotNull] IDbConnection connection,
[NotNull] IDbTransaction transaction,
string jobId,
string queue)
{
if (storage == null) throw new ArgumentNullException(nameof(storage));
if (connection == null) throw new ArgumentNullException(nameof(connection));
if (transaction == null) throw new ArgumentNullException(nameof(transaction));
if (jobId == null) throw new ArgumentNullException(nameof(jobId));
if (queue == null) throw new ArgumentNullException(nameof(queue));
_storage = storage;
_connection = connection;
_transaction = transaction;
JobId = jobId;
Queue = queue;
if (!_storage.IsExistingConnection(_connection))
{
_timer = new Timer(ExecuteKeepAliveQuery, null, KeepAliveInterval, KeepAliveInterval);
}
}
示例8: BuildStatement
public override IDbStatement BuildStatement(
IDbConnection connection,
IDbTransaction transaction,
params IDisposable[] resources)
{
return new FirebirdDbStatement(this, connection, transaction, resources);
}
示例9: UnitOfWork
public UnitOfWork(IDbTransaction transaction, Action<UnitOfWork> rolledBack, Action<UnitOfWork> committed)
{
Transaction = transaction;
_transaction = transaction;
_rolledBack = rolledBack;
_committed = committed;
}
示例10: Insert
public IEnumerable<IDictionary<string, object>> Insert(AdoAdapter adapter, string tableName, IEnumerable<IDictionary<string, object>> data, IDbTransaction transaction, Func<IDictionary<string,object>, Exception, bool> onError, bool resultRequired)
{
var table = adapter.GetSchema().FindTable(tableName);
var columns = table.Columns.Where(c => !c.IsIdentity).ToList();
string columnList = string.Join(",", columns.Select(c => c.QuotedName));
string valueList = string.Join(",", columns.Select(c => "?"));
string insertSql = "insert into " + table.QualifiedName + " (" + columnList + ") values (" + valueList + ")";
var helper = transaction == null
? new BulkInserterHelper(adapter, data, table, columns)
: new BulkInserterTransactionHelper(adapter, data, table, columns, transaction);
if (resultRequired)
{
var identityColumn = table.Columns.FirstOrDefault(col => col.IsIdentity);
if (identityColumn != null)
{
var identityFunction = adapter.GetIdentityFunction();
if (!string.IsNullOrWhiteSpace(identityFunction))
{
return InsertRowsAndReturn(adapter, identityFunction, helper, insertSql, table, onError);
}
}
}
helper.InsertRowsWithoutFetchBack(insertSql, onError);
return null;
}
示例11: Create
/// <summary>
///
/// </summary>
/// <param name="dbConnection"></param>
/// <param name="storedProcName"></param>
/// <param name="parameters"></param>
/// <param name="dbTransaction"></param>
/// <param name="commandTimeout"></param>
/// <param name="commandType"></param>
/// <returns></returns>
public IGridReader Create(IDbConnection dbConnection, string storedProcName, IList<IDbParameter> parameters = null, IDbTransaction dbTransaction = null, int? commandTimeout = null,
CommandType? commandType = null)
{
var dynamicParameters = ConvertToDynamicParameters(parameters);
return new DapperGridReader(dbConnection.QueryMultiple(storedProcName, dynamicParameters, dbTransaction, commandTimeout, commandType));
}
示例12: Execute
public IEnumerable<ResultSet> Execute(IDictionary<string, object> suppliedParameters, IDbTransaction transaction)
{
var procedure = _adapter.GetSchema().FindProcedure(_procedureName);
if (procedure == null)
{
throw new UnresolvableObjectException(_procedureName.ToString(), string.Format("Procedure '{0}' not found.", _procedureName));
}
var cn = transaction == null ? _adapter.CreateConnection() : transaction.Connection;
using (cn.MaybeDisposable())
using (var command = cn.CreateCommand(_adapter.AdoOptions))
{
command.Transaction = transaction;
command.CommandText = procedure.QualifiedName;
command.CommandType = CommandType.StoredProcedure;
SetParameters(procedure, command, suppliedParameters);
try
{
var result = _executeImpl(command);
if (command.Parameters.Contains(SimpleReturnParameterName))
suppliedParameters["__ReturnValue"] = command.Parameters.GetValue(SimpleReturnParameterName);
RetrieveOutputParameterValues(procedure, command, suppliedParameters);
return result;
}
catch (DbException ex)
{
throw new AdoAdapterException(ex.Message, command, ex);
}
}
}
示例13: CreateCommand
public static IDbCommand CreateCommand(IDbConnection db, IDbTransaction transaction, string sql, params object[] parameters)
{
IDbCommand cmd;
// handle named/numbered etc parameters, fixing sql if required.
var new_parameters = new List<object>();
sql = ParseParameters(sql, parameters, new_parameters);
parameters = new_parameters.ToArray();
sql = sql.Replace("@@", "@"); // remove double escaped
cmd = db.CreateCommand();
cmd.CommandText = sql;
//cmd.CommandTimeout = commandTimeout;
//cmd.CommandType = commandType;
if (transaction != null)
{
cmd.Transaction = transaction;
}
foreach (var param in parameters)
{
AddParameter(cmd, param);
}
return cmd;
}
示例14: ConvertQualityProfiles
private void ConvertQualityProfiles(IDbConnection conn, IDbTransaction tran)
{
var qualityProfileItemConverter = new EmbeddedDocumentConverter(new QualityIntConverter());
// Convert 'Allowed' column in QualityProfiles from Json List<object> to Json List<int> (int = Quality)
using (IDbCommand qualityProfileCmd = conn.CreateCommand())
{
qualityProfileCmd.Transaction = tran;
qualityProfileCmd.CommandText = @"SELECT Id, Allowed FROM QualityProfiles";
using (IDataReader qualityProfileReader = qualityProfileCmd.ExecuteReader())
{
while (qualityProfileReader.Read())
{
var id = qualityProfileReader.GetInt32(0);
var allowedJson = qualityProfileReader.GetString(1);
var allowed = Json.Deserialize<List<Quality>>(allowedJson);
var items = Quality.DefaultQualityDefinitions.OrderBy(v => v.Weight).Select(v => new ProfileQualityItem { Quality = v.Quality, Allowed = allowed.Contains(v.Quality) }).ToList();
var allowedNewJson = qualityProfileItemConverter.ToDB(items);
using (IDbCommand updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = "UPDATE QualityProfiles SET Items = ? WHERE Id = ?";
updateCmd.AddParameter(allowedNewJson);
updateCmd.AddParameter(id);
updateCmd.ExecuteNonQuery();
}
}
}
}
}
示例15: BeginConversationInternal
private static Guid BeginConversationInternal(IDbTransaction transaction, string initiatorServiceName, string targetServiceName, string messageContractName, int? lifetime, bool? encryption) {
EnsureSqlTransaction(transaction);
var cmd = transaction.Connection.CreateCommand() as SqlCommand;
var query = new StringBuilder();
query.Append("BEGIN DIALOG @ch FROM SERVICE " + initiatorServiceName + " TO SERVICE @ts ON CONTRACT @cn WITH ENCRYPTION = ");
if (encryption.HasValue && encryption.Value)
query.Append("ON ");
else
query.Append("OFF ");
if (lifetime.HasValue && lifetime.Value > 0) {
query.Append(", LIFETIME = ");
query.Append(lifetime.Value);
query.Append(' ');
}
var param = cmd.Parameters.Add("@ch", SqlDbType.UniqueIdentifier);
param.Direction = ParameterDirection.Output;
param = cmd.Parameters.Add("@ts", SqlDbType.NVarChar, 256);
param.Value = targetServiceName;
param = cmd.Parameters.Add("@cn", SqlDbType.NVarChar, 128);
param.Value = messageContractName;
cmd.CommandText = query.ToString();
cmd.Transaction = transaction as SqlTransaction;
var count = cmd.ExecuteNonQuery();
var handleParam = cmd.Parameters["@ch"] as SqlParameter;
return (Guid)handleParam.Value;
}