473,320 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

trouble retrieving data from ASPState Database

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"))
------------------------------------------------------------
The exception content is as follows:

System.InvalidOperationException: Invalid attempt to read when no data is present. at System.Data.SqlClient.SqlDataReader.PrepareRecord( Int32 i) at System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at System.Data.SqlClient.SqlDataReader.get_Item(Strin g name) at ASP.AgreementListing_aspx.Page_Load(Object Sender, EventArgs E) in C:\Inetpub\wwwroot\onehour\AgreementListing.aspx:l ine 82
Nov 18 '05 #1
2 2229
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" <Gl*********@discussions.microsoft.com> wrote in message
news:BB**********************************@microsof t.com...
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"))
------------------------------------------------------------
The exception content is as follows:

System.InvalidOperationException: Invalid attempt to read when no data is

present. at System.Data.SqlClient.SqlDataReader.PrepareRecord( Int32 i) at
System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at
System.Data.SqlClient.SqlDataReader.get_Item(Strin g name) at
ASP.AgreementListing_aspx.Page_Load(Object Sender, EventArgs E) in
C:\Inetpub\wwwroot\onehour\AgreementListing.aspx:l ine 82
Nov 18 '05 #2
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!!

"mark" wrote:
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" <Gl*********@discussions.microsoft.com> wrote in message
news:BB**********************************@microsof t.com...
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"))
------------------------------------------------------------
The exception content is as follows:

System.InvalidOperationException: Invalid attempt to read when no data is

present. at System.Data.SqlClient.SqlDataReader.PrepareRecord( Int32 i) at
System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) at
System.Data.SqlClient.SqlDataReader.get_Item(Strin g name) at
ASP.AgreementListing_aspx.Page_Load(Object Sender, EventArgs E) in
C:\Inetpub\wwwroot\onehour\AgreementListing.aspx:l ine 82

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bryan Ax | last post by:
Quick question regarding best practices for using the AspState database for storing session variables in .NET web applications. I know I need to configure the web.config file with a database user...
2
by: Kevin Jackson | last post by:
We are stress testing our application. We see 100 SPIDS connected to the ASPSTATE and then the pages request per unit time slow down to barely nothing. It appears that somehow the ASP.NET...
0
by: Eduardo Rosa | last post by:
Hi, I'm reading a ms tutorial about session in asp.net, and I' can't start the aspstate, somebody can help me? tutorial:...
0
by: Tim Greenwood | last post by:
We just discovered that the "temp' database ASPState is in full recovery mode. Is this necessary? Seems ridiculously overkill seeing that when we reboot the sql server machine we really don't...
0
by: Andy | last post by:
Hi All. I'm working for a company that has set out a guideline for retrieving data from a database. Nobody can explain to me the reason for the following. When retrieving a set of records...
2
by: tcw | last post by:
We would like to use ASPState to handle the session State. Since we have several web applications (web sites) in our web server, do we have to create an ASPState database for each web application...
0
by: msnews.microsoft.com | last post by:
We are running a ASP.NET 1.1 web app on Windows Server 2003 SP1. We are using IIS 6.0 native mode and .NET 1.1 SP1 is installed. We have 3 web apps in our web farm. We are using SQLServer...
0
by: Kevin Jackson | last post by:
We are running a ASP.NET 1.1 web app on Windows Server 2003 SP1. We are using IIS 6.0 native mode and .NET 1.1 SP1 is installed. We have 3 web apps in our web farm. We are using SQLServer...
1
by: =?Utf-8?B?RWQ=?= | last post by:
I presently have an ASP.NET 2.0 application in production, that uses a state database "ASPState". I have another seperate application that has the same requirment. Is there any problem with...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.