ASP and ADODB.Connection

Results 1 to 9 of 9

Thread: ASP and ADODB.Connection

  1. #1
    Fred Guest

    Default ASP and ADODB.Connection

    hi all,<BR><BR>When I create a DSN less connection to the SQL Server in my web application&#039s Session_OnStart, I am creating a Connection using the ADODB.connection. Lets call this object conMyConection.<BR><BR>In one of my pages I am creating a sql statement that I want to run against the SQL Server, does the connection object I created earlier remains alive and gets carried over into all the pages that I have for that session OR do I have to create a new Object for every page. <BR><BR><BR>Also say if I create a recordset object rsMyRecordset in the Session_OnStart, can I use that same object in all the rest of the pages? If yes then how long(time) will the object be alive that I will be able to use? Or do I have to recreate the Object in the asp page?<BR><BR>Would help if you have a code snippet!<BR><BR>Fred

  2. #2
    Vivek Nama Guest

    Default RE: ASP and ADODB.Connection

    it is not the connection object directly that will be visible on other pages if opened from a global.asa page<BR>in case you want to do so assign the con object to a session variable and then access the session variable whereever you want

  3. #3
    Fred Guest

    Default RE: ASP and ADODB.Connection

    Thanks for the reply. <BR><BR>Let me rephrase what you just said and tellme if I am correct.<BR><BR>After making the connection object in the Session_OnStart, I can assign the object to a session variable and it will be active till I reach the Session_OnEnd where it will die. Correct? <BR><BR>Can I do the same thing with a recordset object (a session wide variable)? <BR><BR>Is this a safe way to do it?<BR><BR><BR>Thanks.<BR><BR>Fred

  4. #4
    Join Date
    Dec 1969
    Posts
    572

    Default RE: ASP and ADODB.Connection

    I&#039d recommend to create new connection and recordset object on every page, and then kill it at the end of that page. It&#039ll be much safer.


  5. #5
    Fred Guest

    Default To Vivek Nama- RE: ASP and ADODB.Connection

    Adding to my previous reply. <BR><BR>I have a session wide variable on the Session_OnStart, then wont that variable be lost when the session Times-Out????<BR><BR>If the session times-out then the Session_OnEnd will fire where I am setting the object=Nothing, so won&#039t I also lose all the session variables?<BR><BR>If my guess is corect above, I might have to all the time make a reconnection to the database, create a recordset and run my SQL. If I do this then, does this also happen when a user refresses the page?????<BR><BR>Confused Fred!!!!!<BR>&#039elp!!

  6. #6
    Fred Guest

    Default RE: ASP and ADODB.Connection

    Thanks for the reply.<BR><BR>I was thinking along the same line but was not sure if it was the right way to doit!! But I thought that, that is a lot of code I am putting on each and every page? That would be toooo much code being repeated on all the pages.<BR><BR>Is this the right way to do it also???? or is there a better way? I am using VBScript and IIS.<BR><BR>Fred<BR>

  7. #7
    Join Date
    Dec 1969
    Posts
    572

    Default RE: ASP and ADODB.Connection

    First - It&#039s much better then having ADO stored in session variable. Try to stay away from sessions as much as possible, especialy when it comes to the objects. There is an article on 4GuysFromRolla about Session variables. Read it, it&#039ll explain everything.<BR>Second - you can have all the script that creates and initializes ADO components in an include file, so you don&#039t have to have it on every page (you write it once, and then include it to every page, where you need the connection).

  8. #8
    Join Date
    Dec 1969
    Posts
    572

    Default RE: ASP and ADODB.Connection

    Another thing - you can have server side .dll to connect and return the recordset to you, and then just use it to populate ASP; or server side script - either one is better than Session level variables.

  9. #9
    Vivek Nama Guest

    Default RE: To Vivek Nama- RE: ASP and ADODB.Connection

    As truly pointed out by Alex it is always advantageous to handle ADO thru an include file on each ASP Page <BR>I thought your question was if you HAVE TO do ADO handling globally what&#039s the best way of doing it<BR>sorry for that ..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •