sqlWrite.ExecuteNonQuery();
数秒で 200 個の挿入クエリを実行した後、コードでエラーが発生することに気付きました。using
これにより、リソースが適切に再利用され、何もする必要がなくなると常に考えていました。このエラーが発生するのはこれが初めてで、SQL/C# をほぼ 3 年間、さまざまなことを行ってきました。
using (SqlConnection varConnection = Locale.sqlConnectOneTime(Locale.sqlDataConnectionDetails))
{
using (var sqlWrite = new SqlCommand(preparedCommand, varConnection))
{
sqlWrite.Parameters.AddWithValue("@var_agr_fname", var_agr_fname == "" ? (object) DBNull.Value : var_agr_fname);
sqlWrite.ExecuteNonQuery();
}
}
public static SqlConnection sqlConnectOneTime(string varSqlConnectionDetails)
{
var sqlConnection = new SqlConnection(varSqlConnectionDetails);
try
{
sqlConnection.Open();
}
catch
{
DialogResult result = MessageBox.Show(new Form {TopMost = true},
"Błąd połączenia z bazą danych. Czy chcesz spróbować nawiązac połączenie ponownie?",
"Błąd połączenia (000001)",
MessageBoxButtons.YesNo,
MessageBoxIcon.Stop);
if (result == DialogResult.No)
{
if (Application.MessageLoop)
{
Application.Exit(); // Use this since we are a WinForms app
}
else
{
Environment.Exit(1); // Use this since we are a console app
}
}
else
{
sqlConnection = sqlConnectOneTime(varSqlConnectionDetails);
}
}
return sqlConnection;
}
エラーメッセージ:A transport-level error has occurred when sending the request to the server. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)
このエラーのアドバイスを考慮してSqlConnection.ClearAllPools();
、接続が適切にリセットまたは破棄されていることを確認するために使用する必要があります。だから私はそれを使うことができますが、問題はそれをいつどこで使うかです。制限が破られるかどうかを知る方法は?どこが限界?50 / 150 / 200 ? または、ループで毎回使用する必要がありますか?