このように見えるコードがいくつかあります(エラー処理やその他のものは削除されています)
using (var tran = conn.BeginTransaction())
{
var client = new Service(...);
var dialog = client.GetConversation(null, conn, tran);
var response = dialog.Receive();
// do stuff with response, including database work
dialog.Send(message, conn, tran);
dialog.EndConversation(conn, tran);
tran.Commit();
conn.Close();
}
私たちはこのコードを継承しており、ServiceBrokerの専門家ではありません。次のように、会話をトランザクションの外に移動すると問題が発生します。
var client = new Service(...);
var dialog = client.GetConversation(null, conn, tran);
var response = dialog.Receive();
using (var tran = conn.BeginTransaction())
{
// do stuff with response, including database work
tran.Commit();
}
dialog.Send(message, conn, tran);
dialog.EndConversation(conn, tran);
conn.Close();