Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

session datareader, is that possible? 1

Status
Not open for further replies.

StylizIT

Programmer
Dec 4, 2003
62
NL
hi folks, I was wondering if it is possible to have a datareader linked to a session, so that every user that logs in, will have his own datareader that's assosiated to his session.

The reason I'm asking is because I'm having some problems with my asp.net application. I'm designing a contract managment systeem for a company. It has to be a multi-user application.

it already supports multi user login etc. but the problem I'm having is that when 2 or more users try to read from the database, the application will sometimes give me the error: there's already a datareader open which must be closed first.

I've already use session variables to store data so that each user will have its own variables, and that helped alot already to make my application multi user.

You can better regret that you have done something than regret the fact you done nothing
 
what does your code look like? do you use the new keyword when delcaring your vairables for the database connection? if you get that error there is already another instance of the data reader open that one must be close before the next one can open.

what do you do with the data in the data reader? You should move it to an object that can exists outside a database connection.

Jason Meckley
Database Analyst
WITF
 
thanks for your reply m8,
well, I've created several forms with textboxes and dropdownlists which are filled with data everytime the user requests some information about a contract.
That's basically what happens, but while testing my application, I with two users being logged in and requesting information I received this error a few times. But I'll do some more testing and explain in a more specific way to you what that problem is so you could help me out. I'll get back to you tomorrow gonna get me some sleep now

thanks in advance

PS. everywher ein my code I'm declaring the readers like this:

Dim myreaderW As Odbc.OdbcDataReader = Odbccommnd.ExecuteReader()

think that might be one of the reasons it will generate errors when multiple users are using my application?


You can better regret that you have done something than regret the fact you done nothing
 
When executing the OdbcDataReader, close the db connection as well. Close OdbcDataReader after you're done with it:
Code:
Dim myreaderW As Odbc.OdbcDataReader = Odbccommnd.ExecuteReader(CommandBehavior.CloseConnection)
'process data
myreaderW.Close()
See if this helps.
 
the problem is I have 1 connection open troughout the whole application that's being used by the readers etc. I don't wan't to close it at all. That's why I didn't try closing the connection all the time. But here's another thing. Do you think that it matters if I declare the same readers on every page?

For exmaple I delcare myreader 1 on page a, and myreader 1 also on page 2. Then if user 1 opens page 1, myreader1 will be declared. But when user 2 logs in and opens page 2, myreader1 on page 2 will also be declared. Do you think that might cause problems?

You can better regret that you have done something than regret the fact you done nothing
 
But disconnected data is one of (in my opinion) the best things about .Net.

Do you actually need to hold a connection open throughout the scope of the Application? It's actually highly unlikely that you do and is likely to be the cause of your problems here. It would probably be better to have an Appliction or page scoped Connection object which you open and close as required using try...catch...finally blocks.

What I've done in the past is have page scoped connection objects, which are opened, closed and displosed of as required using try...catch...finally and I'm yet to hear of a connection already open problem in any application I've worked on.

Rhys
Buffy: Spike, what are you doing here, five words or less!
Spike: Out for a walk... bitch!
 
thanks for your reply, I think I don't have a choice then, I will do this and see what happens;)

thanks again.

You can better regret that you have done something than regret the fact you done nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top