C#前台使用事务调用存储过程的问题 前台是使用了事务调用的存储过程中又有事务,这样可行吗?会不会超级影响效率,sqlserver数据库很多人同时用到这个存储过程,因为前台还要同时执行其他的命令和操作,大虾们!事务存储sqlserver数据库c# 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那样使用是没有问题的,参考:public ExecuteResult ExecuteNonQuery(SqlCommand sqlCommand){ ChangeNullToDBNullValue(sqlCommand); bool useDefaultConnection = false; if (sqlCommand.Connection == null) { useDefaultConnection = true; sqlCommand.Connection = new SqlConnection(this.connectionString); } else { useDefaultConnection = false; if (sqlCommand.Connection.State != ConnectionState.Closed) { throw new ArgumentException("SqlCommand's connection state must be closed."); } } sqlCommand.Connection.Open(); sqlCommand.Transaction = sqlCommand.Connection.BeginTransaction(); try { int rows = sqlCommand.ExecuteNonQuery(); sqlCommand.Transaction.Commit(); return new ExecuteResult() { ActionStatus = ActionStatusType.Success, ReturnValue = rows }; } catch (SqlException ex) { sqlCommand.Transaction.Rollback(); DBOperatorLogsWritter.WriteDBErrorLog(ex, sqlCommand); return new ExecuteResult() { ActionStatus = ActionStatusType.Fail, Message = ex.Message }; } finally { sqlCommand.Connection.Close(); if (useDefaultConnection) { sqlCommand.Connection = null; } }} 你存储过程里都有事务了 后台就不需要写了 直接调用就行了..如果还害怕有问题 大不了在存储过程里加 try catch 这样就行了 除法怎么得到余数啊 Application.DoEvents用法 两个字符串相比较如何取出相同部分 winform的toolbar要怎么设置字体颜色? C#的环境变量 TrackingLayer的问题!!!在线等,谢谢大家!!! C# 数据库 问题 我在C#中接收Email的问题 大家来讨论下程序员的发展方向 求一个关于正规表达式的问题 如何调用系统照相机 Winform的 Button 的 鼠标 和 空格 事件 ??按下弹起状态??
{
ChangeNullToDBNullValue(sqlCommand);
bool useDefaultConnection = false;
if (sqlCommand.Connection == null)
{
useDefaultConnection = true;
sqlCommand.Connection = new SqlConnection(this.connectionString);
}
else
{
useDefaultConnection = false;
if (sqlCommand.Connection.State != ConnectionState.Closed)
{
throw new ArgumentException("SqlCommand's connection state must be closed.");
}
}
sqlCommand.Connection.Open();
sqlCommand.Transaction = sqlCommand.Connection.BeginTransaction();
try
{
int rows = sqlCommand.ExecuteNonQuery();
sqlCommand.Transaction.Commit();
return new ExecuteResult() { ActionStatus = ActionStatusType.Success, ReturnValue = rows };
}
catch (SqlException ex)
{
sqlCommand.Transaction.Rollback();
DBOperatorLogsWritter.WriteDBErrorLog(ex, sqlCommand);
return new ExecuteResult() { ActionStatus = ActionStatusType.Fail, Message = ex.Message };
}
finally
{
sqlCommand.Connection.Close();
if (useDefaultConnection)
{
sqlCommand.Connection = null;
}
}
}