SQLでCCRを実装する際に問題が発生しました。コードをステップスルーすると、更新と挿入をうまく実行しようとしているようです。しかし、ブレークポイントなしでインターフェイスを実行すると、動作しているように見え、挿入、更新が表示されますが、実行の最後に、データベースに何も更新されませんでした。
プールから新しいスレッドをプルするたびにコードに一時停止を追加しましたが、それは機能します...しかし、それは非同期コーディングの目的を無効にしますか?インターフェースを遅くするのではなく、速くしたい...
任意の提案...ここに私のコードの一部があります:
2つのヘルパークラスを使用してポートを設定し、応答を返します...
/// <summary>
/// Gets the Reader, requires connection to be managed
/// </summary>
public static PortSet<Int32, Exception> GetReader(SqlCommand sqlCommand)
{
Port<Int32> portResponse = null;
Port<Exception> portException = null;
GetReaderResponse(sqlCommand, ref portResponse, ref portException);
return new PortSet<Int32, Exception>(portResponse, portException);
}
// Wrapper for SqlCommand's GetResponse
public static void GetReaderResponse(SqlCommand sqlCom,
ref Port<Int32> portResponse, ref Port<Exception> portException)
{
EnsurePortsExist(ref portResponse, ref portException);
sqlCom.BeginExecuteNonQuery(ApmResultToCcrResultFactory.Create(
portResponse, portException,
delegate(IAsyncResult ar) { return sqlCom.EndExecuteNonQuery(ar); }), null);
}
それから私は私の呼び出しをキューに入れるためにこのようなことをします...
DispatcherQueue queue = CreateDispatcher();
String[] commands = new String[2];
Int32 result = 0;
commands[0] = "exec someupdateStoredProcedure";
commands[1] = "exec someInsertStoredProcedure '" + Settings.Default.RunDate.ToString() + "'";
for (Int32 i = 0; i < commands.Length; i++)
{
using (SqlConnection connSP = new SqlConnection(Settings.Default.nbfConn + ";MultipleActiveResultSets=true;Async=true"))
using (SqlCommand cmdSP = new SqlCommand())
{
connSP.Open();
cmdSP.Connection = connSP;
cmdSP.CommandTimeout = 150;
cmdSP.CommandText = "set arithabort on; " + commands[i];
Arbiter.Activate(queue, Arbiter.Choice(ApmToCcrAdapters.GetReader(cmdSP),
delegate(Int32 reader) { result = reader; },
delegate(Exception e) { result = 0; throw new Exception(e.Message); }));
}
}
ここで、ApmToCcrAdaptersは、ヘルパーメソッドが存在するクラス名です...
問題は、Arbiter.Activateを呼び出した直後にコードを一時停止し、データベースをチェックすると、すべてが正常に見えることです...一時停止広告を削除すると、コードが実行され、データベースには何も起こらず、例外もありませんどちらかがスローされます...