Results 1 to 5 of 5

Thread: Error accesing Session variable

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    266

    Question

    Hi all,
    -------------------------------------
    The code in my global.asa file is as follows

    <SCRIPT LANGUAGE=VBSCRIPT RUNAT=SERVER>

    Sub Session_OnStart

    Set Session("Cnn") = Server.CreateObject("ADODB.Connection")
    Session("Cnn").Provider="Microsoft.Jet.OLEDB.4.0"
    Session("Cnn").Open "C:\Inetpub\wwwroot\Test.mdb"
    End Sub

    Sub Session_OnEnd
    Session("Cnn").Close
    End Sub

    </SCRIPT>

    ---------------------------------------
    I have created an ActiveX DLL which uses Microsoft Active Server Pages Object Library
    The code in its class file is as follows.

    Private ASPResponse As Response
    Private ASPSession As Session

    Public Sub OnStartPage(sc As ScriptingContext)
    Set ASPResponse = sc.Response
    Set ASPSession = sc.Session
    End Sub

    Public Sub PleaseRetrieve()
    Dim rs As New ADODB.Recordset
    rs.Open "Select * FROM ABCD", ASPSession("Cnn"), adOpenKeyset, adLockOptimistic, adCmdText
    'It gives me an error in the above statement. The error message is Run-time error 3001: the application is using arguments that are of the wrong type.
    'The error is being caused due to the argument ASPSession("Cnn") which is actually valid as it is being created in the global.asa script
    End Sub

    ----------------
    Thanks in advance

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    You are storing a connection object in the session variable? You are a BAD BAD BAD BAD BAD boy

    Seriously though, don't do this for performance reasons. MTS and/or IIS will pool your database connections, so all of your DLL functions should explictly create a connection object, do its work, then destroy the connection.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    266
    Thanks a lot Clunietp. But then when should one be using these session and application variables. Also any info source for the do's and dont's in ASP.

  4. #4
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Sudbury, Ontario, Canada
    Posts
    274

  5. #5
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    Use session & application variables sparingly, as they eat up memory. I never use session or application variables anymore, I usually use querystrings or hidden form variables, and keep as much state as possible on the client using cookies

Posting Permissions

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



Click Here to Expand Forum to Full Width