1
WCFサービスでデータベースに非同期で接続しようとしています。しかし、接続文字列に「非同期処理= true」を設定するのにもかかわらず、私はメッセージでWCFサービスのBeginExecuteReaderエラー
System.InvalidOperationException
を取得していますBeginExecuteReader: Connection property has not been initialized.
私は、データベースへの接続に使用しているコードは次のとおりです。
public void Connect()
{
using (SqlConnection conn = new SqlConnection("Data Source=User12-PC; Initial Catalog = BMS; User Id=sa; Password = pass; Asynchronous Processing=true"))
{
SqlCommand command = new SqlCommand();
command.CommandText = "Select l.currvalue from" +
" advt_ctrl_pts as p inner join advt_log_in_ctrl_pts l" +
" on p.registerid = l.regid and p.ddcid = l.ddcid" +
" where p.pointid = 5156102" +
" order by datetime";
command.CommandType = CommandType.Text;
conn.Open();
IAsyncResult result = command.BeginExecuteReader(); //This part is returning exception
if (result.IsCompleted)
{
timer = new Timer(new TimerCallback(onTimerTick), command.EndExecuteReader(result), 5000, 5000);
}
}
}
誰でも何が問題なのか教えてください。
も '新しいSqlCommandオブジェクト( "選択..."、conn)を使用することができます;'など。 –