- PR -

SQLCLRでのトランザクション

1
投稿者投稿内容
CAS
会議室デビュー日: 2006/09/13
投稿数: 1
投稿日時: 2006-09-13 17:55
2つのトランザクションを利用するストアドプロシージャを作成しようとしているのですが、コンテキスト接続は1つしか使えないため以下のような方法を取ろうと考えています。

コード:

Sqlconnection connection1 = new Sqlconnection(サーバへの接続文字列);
Sqlconnection connection2 = new Sqlconnection(上と同じ接続文字列);

connection1.Open();
connection2.Open();

SqlTransaction tran1 = connection1.BeginTransaction();
SqlTransaction tran2 = connection2.BeginTransaction();

SqlCommand command1 = new SqlCommand();
command1.Connection = connection1;
command1.Transaction = tran1;

SqlCommand command2 = new SqlCommand();
command2.Connection = connection2;
command2.Transaction = tran2;

try
{
for(int i = 0;i < 10; i++)
{
SqlCommandを使い何らかの処理を行う。
}
tran1.Commit();
}
catch
{
tran1.RollBack();
}
tran2.Commit();

connection1.Close();
connection2.Close();



上記のようなコードを記述してみたのですが、ビルドと配置はできるのですが、実行した際にサーバが応答せずにタイムアウトしてしまいます。

この解決方法か別の手法をアドバイスしていただけたらと思います。
よろしくお願いします。

[ メッセージ編集済み 編集者: CAS 編集日時 2006-09-15 18:32 ]

[ メッセージ編集済み 編集者: CAS 編集日時 2006-09-15 18:32 ]
1

スキルアップ/キャリアアップ(JOB@IT)