View Full Version : Global.asa and Session variable
ScottInTexas
06-06-2003, 03:08 PM
In my localhost this works fine but when I publish it to the intranet I get the following error when trying to access a database.
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/funcs.asp line 36
The line it is referencing is in this;
SQL="SELECT YearID FROM Production GROUP BY YearID ORDER BY YearID;"
With MainRS
.CursorType = 1
.Open SQL, session("DBConn")
End With
And the session variable is set in the global.asa ;
Sub Session_onStart()
Set DBConn=Server.CreateObject("ADODB.Connection")
With DBConn
.Provider="Microsoft.Jet.OLEDB.4.0"
.Open(Server.MapPath("/virtual/data/databases/LHCTech/LHC_Perf_Metrics.mdb"))
End With
Set session("DBConn")=DBConn
End Sub
Am I using the session variable wrong? I access the DB a lot and thought it would save a lot of server time if I made one connection and kept using it until the user left.
For the localhost testing I have a duplicate database in the wwwroot/database folder. When I move to the intranet I replace the line with the intranet path to the data. I would think I'd get a different error if the file couldn't be found.
Thanks,
(sure there was an active session?)
This shouldn't be in a sessionvariabel, since it is not clientspecific. It would make more sense to place it inside an applicationvariabel
Hmm. I've read something somewhere about this but i can't remeber if it was good or bad practice.
My impression is that it's a 'bad' practise.
- Each connection then mean you need to make a call to the application-object (which takes resources). I always store the connectionstrings inside a SSI (server side include)with an ASP extension. I think it performs better (but i could be wrong)
- Storing it in a SSI allows you to change the connectionstrings, while the application keeps running. If you store the connections in a session or applicationvariabel that is set in the global.asa, then you can't change anything on that code without restarting the application (if you modify you global.asa, the application is restarted --> which means all sessions get destoyed and all applicationvariabels get set to nothing)
- a suppose it would be possible for an evil client to get the value from the appliationvariable (certainly with an obvious variabelname as DBconn) where it's a lot harder to get to the adres of the include + if it has an asp or php or jsp ... extension, it can't be opened in the browser and will always be parsed.
I always use the SSI method.
ScottInTexas
06-06-2003, 04:03 PM
Thanks RAF,
I had originally set up a SSI but thought that calling it repeatedly (DBConn=GetConn) was using more resources. It seems to me that everytime that function ran the server was going through a lot of paces just to give me a connection.
Your argument about the changing of the connection string etc. was considered but since I am just displaying different rows of data from the same database the connection string would never change.
I'm going back to the SSI and calling this page done. Thanks again for your help.
the connection string would never change.
quote=replace(quote,"never","someday") ;)
I alsom meant 'when you move your db or replace it'.
About resources. Hmm. I don't know which eats away 'most' resources, but i don't think that's the decisive difference/argument (Just my opinion)
As long as you close all recordsets and connections + set them to nothing, i wouldn't mint to much about optimizing the way you implement your db-interaction.
Roy Sinclair
06-06-2003, 05:16 PM
See tip number 5.
http://msdn.microsoft.com/library/default.asp?URL=/library/en-us/dnasp/html/ASPtips.asp
ScottInTexas
06-06-2003, 05:57 PM
OK, maybe not never, but certainly not for a very long time.
:)
afifaumer
06-10-2003, 01:32 PM
Dear friend......... The thing you discussed that you are facing the problem in using global.asa online. Actually i want to tell you that i faced this kind of problem too. I made two projects in a row. first was having the global.asa support but the second was not. The project which having the global.asa support create the problem when i published my project on the server. then i asked directly to the server that it was working proprly offline why is it now ? they said that by default we stoped the global.asa files by anti virus on the server. because these files cause to make the virus. so after that they clear the asa sopprting files and charge from me 500 RS. (Pakistani rupee). Till now i didn't get the problem like that... not the session's and not about any query or any other thing.... Some times it gives error in that pages in asp in which we use "Response.Redirect". We have to write at the top of the page. <%Response.Buffer=True%>
Take Care
Regards
Afifa Umer
Never heard of a host blocking global.asa files. Strange motivation to ("because it is making viruses" --> suppose you mean spreading viruses). I really wouldn't see how that could happen.
Using a global.asa file and performing an IP check there, seems like a good standard defence against denial of service attacks and for keeping out unwanted clients. So it wouldn't be very smart do disable it for security reasons. (In fact, i'd rather hit there server or switch host then to pay them for enabeling global.asa support)
About the redirect --> buffering the output is good practise for almost all pages. But i frankly don't see why you would have any output before you redirect. Never had a problem with asp's using redirect, even if i don't buffer the output (cause there isn't any). In fact, i do think that buffering the output there will have a negative effect on the servers performance
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.