trouble retrieving data from ASPState Database

G

Guest

I'm trying to put together a web form that lists all current session information. The session info is stored in SQL server database (ASPState) and I'm trying to retreive and display using a SQLDataReader. I seem to have no trouble querying the "ASPStateTempSessions" table but when I try to write it to the page, I throw an exception that basically says that there is no data to display. Is there some special method you must use when performing this sort of task?
The code is as follows:
------------------------------------------------------------
dim cn as new SqlConnection(ConfigurationSettings.AppSetting ("ASPState").toString())
cn.Open()
dim cmd as new SqlCommand("select * from ASPStateTempSessions where TimeOut = 40", cn)
dim dr as SqlDataReader
dr = cmd.ExecuteReader()
Response.Write(dr("Locked"))
 
M

mark

when using a datareader, you have to first call the "read" method.

dr = cmd.ExecuteReader()
dr.read()
Response.Write(dr("Locked"))

OR to get all rows:

do while dr.read()
Response.Write(dr("Locked"))
loop (i think)




Glenn Venzke said:
I'm trying to put together a web form that lists all current session
information. The session info is stored in SQL server database (ASPState)
and I'm trying to retreive and display using a SQLDataReader. I seem to have
no trouble querying the "ASPStateTempSessions" table but when I try to write
it to the page, I throw an exception that basically says that there is no
data to display. Is there some special method you must use when performing
this sort of task?
The code is as follows:
------------------------------------------------------------
dim cn as new SqlConnection(ConfigurationSettings.AppSetting ("ASPState").toString())
cn.Open()
dim cmd as new SqlCommand("select * from ASPStateTempSessions where TimeOut = 40", cn)
dim dr as SqlDataReader
dr = cmd.ExecuteReader()
Response.Write(dr("Locked"))
present. at System.Data.SqlClient.SqlDataReader.PrepareRecord(Int32 i) at
System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at
System.Data.SqlClient.SqlDataReader.get_Item(String name) at
ASP.AgreementListing_aspx.Page_Load(Object Sender, EventArgs E) in
C:\Inetpub\wwwroot\onehour\AgreementListing.aspx:line 82
 
G

Guest

Boy, am I a dope! I thought datareader.read worked along the lines of recordset.EOF. I thought it was a simple boolean property that told you if any records were returned or not. But it is actually a method that returns a boolean. I guess you learn something new every day. Thanks much!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top