ASP.NET architecture : am I missing something

J

Julien

Hi folks,

I am facing a little problem with my website that gives me an headache : It
can not have 2 users at the same time (quite annoying, as you see:))
I think I miss something in the ASP.NET architecture, but I can not see why
The problem stands in my connection to the database.

I have a unit that owns a SQLConnection object.
When a page is requested I call a class function that creates the SQL
object.

The fact is that this object seems to be shared amongst the users connected
to the site, when requesting a page at the same time.
That results in some odd errors telling connexion already opened and errors
like this. The problem disapears if only one visitor is connected to the
site.

Can someone help me ?
Thanks,

Julien
 
J

Julien

ok, but this is delphi code ... even if it is quite easy to understand
we use a persistance layer

-----------------------------
unit myUnit;

interface

type
TBDEObject = class(TDMObject)
procedure doSomething;
(...)

implementation

var sqlconn : SQLConnection;

function connect : boolean;
// this function initialize the sqlconn object

procedure TBDEObject.doSomething;
// in this procedure, the object sqlconn is used to work with the
database ...
// but this object seems to be shared amongst users

-------------------------------

In the initialization part of another unit, I call myUnit.connect
In the finalization part, I call myUnit.disconnect

I hope it helps ...

Julien
 
K

Karl Seguin

I'm amused that Juan happened to get the only Delphi.Net question on
here....but I'm inclained to offer any help I can...

First, I don't know anything about Delphi ... but when I first read your
post, I figured you might be making improper use of static/shared members.
So I looked that concept up for Delphi and it turns out it doesn't have
anything exactly like that. A useful newsgroup post did mention that "the
workaround is to use the unit instead - a global var (initialized) or a
typed constant, in the Implementation section," which seems to be exactly
what you have.

In other words, it seems that you've made SqlConn a variable shared by all
instances. Of course, how you declare a private member field vs a static
field in Delphi is beyond me.

I would suggest that in ASP.Net, it's typical for each unit of functionality
to create and open an SqlConnection and close it ASAP where you have:

SqlConnection
Initialize()
DoSomething()
Cleanup()

I'd suggest you simply do:
DoSomething()

which internally has an Sqlconnection which is initialized and cleaned up.

Karl
 
J

Juan T. Llibre

re:
I'm amused that Juan happened to get the only Delphi.Net question

Well, there just wasn't enough info in the post.

I requested more info, but I'd never have
imagined that the question was about Delphi.net.

;-)
 
J

Julien

Karl,

Thanks for your suggestion.
I now open and close the connection before each database manipulation, and
sqlconn is a private object of the class.
If I open the connection in create an close in destroy, I get occasionnaly
the error 'there is already an open DataReader associated with this
Connection '
If I open and close before each database manipulation, I get others problems
showing that there other objects that seem to be shared amongst user ... for
instance I can sometimes grab the basket (which is a class too) of the other
person connected to the site :(
If you have over suggestions, you are welcome :)

Julien
 
J

Julien

well, the point is I don't have actually any datareader, but it fails with
this error on
mySQLDataAdapter.Fill(myTable); !
 
K

Karl Seguin

Fill internally uses a DataReader. Is the connection itself being closed?
Is the DataAdapter being disposed when you are done with it? It really does
sound like cleanup not taking place.

Karl
 
J

Julien

Hi,

I finally found the solution.
In Delphi, global variables defined in an unit are static, so they are
common to every client that connects to the application.
So I have listed all the variable that are client-dependant, then I built
an object with class properties to store these objects in the session
object.
Now it works like a charm :)
Thanks for your help,

Julien
 

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,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top