でDataReaderを使用する場合、私は次のエラーを取得する:私は毎秒タイマーを使用してデータベースから値を読み込もうとしていたときにタイムアウト期限切れエラー:ループ
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll
Additional information: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
です。
以下はコードです。 SQL接続が閉じられていないためです。しかし、私はそれを解決するために何をすることができますか?
public void showcount2(int ID)
{
notifyIcon1.Visible = true;
string count;
string connString = ConfigurationManager.ConnectionStrings["Dbconn"].ToString();
SqlConnection connection = new SqlConnection(connString); // defining sql connection
connection.Open(); // opening connection
SqlCommand cmd1 = connection.CreateCommand();
cmd1.CommandText = "select count from dbo.tblcount where UserID = " + ID;
DataSet datasetFBK1 = new DataSet();
SqlDataAdapter dataadapterFBK1 = new SqlDataAdapter(cmd1);
dataadapterFBK1.Fill(datasetFBK1);
SqlDataReader dr1 = cmd1.ExecuteReader();
if (dr1.Read())
{
string countcheck;
countcheck = notifyIcon2.Text;
count = dr1[0].ToString();
notifyIcon2.Text = "NCT COUNT FOR COLLEAGUE IS: " + count;
if (countcheck == notifyIcon2.Text)
{
return;
}
else
{
notifyIcon2.BalloonTipText = "NCT COUNT FOR COLLEAGUE IS: " + count;
notifyIcon2.ShowBalloonTip(50000);
}
//pick a colored icon based on the count of the NCT cases
if (Convert.ToInt32(count) <= 3)
{
notifyIcon2.Icon = new Icon("C:\\BackupFromPC\\greenicon.ico");
}
else if (Convert.ToInt32(count) > 3 && Convert.ToInt32(count) <= 5)
{
notifyIcon2.Icon = new Icon("C:\\BackupFromPC\\yellowicon.ico");
}
else if (Convert.ToInt32(count) > 5)
{
notifyIcon2.Icon = new Icon("C:\\BackupFromPC\\redicon.ico");
}
//------------------------------
connection.Close();
}
}
は、返信いただきありがとうございます。これはうまくいった。あなたの入力を感謝します。 –