我只是想知道使用Serializable作为默认Isolationlevel的一个很好的理由可能是在创建System.Transactions TransactionScope时,因为我想不出任何(并且似乎你不能改变默认值,web/app.config所以你总是要设置它你的代码)
using(var transaction = TransactionScope())
{
... //creates a Transaction with Serializable Level
}
Run Code Online (Sandbox Code Playgroud)
相反,我总是要写这样的样板代码:
var txOptions = new System.Transactions.TransactionOptions();
txOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
using(var transaction = new TransactionScope(TransactionScopeOption.Required, txOptions))
{
...
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我正在使用C#和ADO.Net TransactionScope来运行ASP.Net应用程序中的事务.此事务应该在多个表中保存一些数据,然后向订阅者发送电子邮件.
问:这是一个有效的使用TransactionScope,当它包括到在SQL Server 2014年自己的事务存储过程的调用,或者我应该删除SQL事务语句,即begin tran,commit tran并且rollback tran从存储过程的语句被内这个叫TransactionScope?
下面提到了此场景的C#代码以及存储过程的T-SQL代码.
C#代码使用TransactionScope:
try
{
using (TransactionScope scope = new TransactionScope())
{
using (SqlConnection connection1 = new SqlConnection(connectString1))
{
// Opening the connection automatically enlists it in the
// TransactionScope as a lightweight transaction.
connection1.Open();
// SaveEmailData is a stored procedure that has a transaction within it
SqlCommand command1 = new SqlCommand("SaveEmailData", connection1);
command1.CommandType = CommandType.StoredProcedure;
command1.ExecuteNonQuery();
}
//Send …Run Code Online (Sandbox Code Playgroud)