複数の挿入を伴うトランザクションがあります。1つを除いて、すべてのインサートが正常に機能します。パラメータ、スペル、すべてを確認しましたが、理解できていないようです。エラーが表示されます:
Timeout expired. The timeout period elapsed prior to completion of the operation
or the server is not responding.
私のトランザクションは次のようになります。
SqlConnection db = new SqlConnection(connString);
DataSet dataSet = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
using (db)
{
db.Open();
SqlTransaction trans = db.BeginTransaction();
try
{
//insert into COMMSignalDefinition !!Problem HERE
da.InsertCommand =
new SqlCommand("INSERT INTO COMMSignalDefinition(Name) "
+ "VALUES (@name)", db, trans);
da.InsertCommand.Parameters.Add("@name", SqlDbType.NVarChar);
foreach (DataRow row in ds.Tables["COMMTerminalSignal"].Select())
{
da.InsertCommand.Parameters[0].Value = row.ItemArray[1];
da.InsertCommand.ExecuteNonQuery();
}
// insert into COMMSignalExceptionDefinition -- names
da.InsertCommand =
new SqlCommand("INSERT INTO COMMSignalExceptionDefinition(Name) "
+ "VALUES (@name)", db, trans);
da.InsertCommand.Parameters.Add("@name", SqlDbType.NVarChar);
foreach (DataRow row in ds.Tables["COMMSignalExceptionDef"].Select())
{
da.InsertCommand.Parameters[0].Value = row.ItemArray[1];
da.InsertCommand.ExecuteNonQuery();
}
trans.Commit();
MessageBox.Show("You have successfully imported your Settings. "
+ "You can now exit the program.",
"Success",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
catch (Exception e)
{
trans.Rollback();
MessageBox.Show(e.Message,
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
正常に動作する挿入がさらにあり(残りの挿入は削除しました)、最初に問題のある挿入を移動しました。私の質問は、何が間違っている可能性がありますか? 「問題のある」クエリがサーバーに送信されるかどうかも確認しましたが、SQL Server Profiler,
そうです! で実行するとSQL Server Management studio
、それも機能します。
Connection Timeout
30に設定されています
手がかりを教えてください。SQL Server のバージョンは 2005 です。ありがとう!