5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

C# .NET FrameworkでTransactionScopeでタイムアウトしてしまうときの対処法

Posted at

TransactionScopeでタイムアウトしてしまうときの対処法
大量のデータを処理する場合、デフォルトの処理時間内にSQLが処理しきれない場合がある

トランザクションのタイムアウト時間は、初期設定では1分

// タイムアウト時間 1分
using (var transaction = new TransactionScope())
{
}

タイムアウト時間を設定するには、TransactionScopeOptionのオプション設定が利用可
例えば、下記のようにタイムアウト時間を設定できる

// タイムアウト時間 10分
using (var transaction = new TransactionScope(
            TransactionScopeOption.Required,
            new System.TimeSpan(0, 10, 0)))
{
}

タイムアウト時間を無制限にすることも可

// タイムアウト時間 無制限
using (var transaction = new TransactionScope(
            TransactionScopeOption.Required, TimeSpan.Zero))
{
}

タイムアウト時間を初期値の最大値である10分を超える設定をする場合、
machine.configに以下を記述する必要

<configuration>
<system.transactions>
  <machineSettings maxTimeout="01:00:00" />
</system.transactions>
</configuration>

machine.configの場所は、例えば64bitのWindowsなら下記の場所にある

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config

Reference

5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?