G
Guest
I'm having a problem reading from a SqlDataReader accessing SQlServer 2000. Part way within a while ( Read() ) loop, I get an exception with the message "Invalid attempt to read data when reader is closed." However, no where in the code is the reader closed. I've tried extending the connect timeout setting, setting the ExecuteReader's CommandBehavior to CommandBehavior.CloseConnection. These seem to help, but only delays the problem. The code follows. ExceuteQuery() is a method that instantiates a SqlCommand object and calls its ExcuteQuery method--nothing fancy. The exeception gets thrown early (anywhere form 400-600 rows), but the query can return as many as 10,000 rows. Any help will be much appreciated
string SQL = string.Format("select Word1 [Word 1], Word2 [Word 2], freq from ContextBigrams where "
"(Word1 = '{0}' and Pos1 = '{1}' and Pos2 = '{2}')"
"or "
"(Word2 = '{0}' and Pos2 = '{1}' and Pos1 = '{2}')"
word.Replace("'","''"),sourcePos,targetPos)
SqlDataReader rdr = ExecuteQuery(SQL)
DataSet ds = new DataSet()
DataTable dt = ds.Tables.Add("Context words")
dt.Columns.Add("Word",typeof(string))
dt.Columns.Add("Freq",typeof(int))
while ( rdr.Read()
DataRow dr = dt.NewRow()
dt.Rows.Add(dr)
dr["Word"] = ( (string)rdr["Word 1"] == word ? rdr["Word 2"].ToString() : rdr["Word 1"].ToString() )
dr["Freq"] = (int)rdr["freq"]
}
rdr.Close()
Thanks
Jim Carpente
string SQL = string.Format("select Word1 [Word 1], Word2 [Word 2], freq from ContextBigrams where "
"(Word1 = '{0}' and Pos1 = '{1}' and Pos2 = '{2}')"
"or "
"(Word2 = '{0}' and Pos2 = '{1}' and Pos1 = '{2}')"
word.Replace("'","''"),sourcePos,targetPos)
SqlDataReader rdr = ExecuteQuery(SQL)
DataSet ds = new DataSet()
DataTable dt = ds.Tables.Add("Context words")
dt.Columns.Add("Word",typeof(string))
dt.Columns.Add("Freq",typeof(int))
while ( rdr.Read()
DataRow dr = dt.NewRow()
dt.Rows.Add(dr)
dr["Word"] = ( (string)rdr["Word 1"] == word ? rdr["Word 2"].ToString() : rdr["Word 1"].ToString() )
dr["Freq"] = (int)rdr["freq"]
}
rdr.Close()
Thanks
Jim Carpente