Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 2nd, 2003, 07:45 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 121
Thanks: 1
Thanked 0 Times in 0 Posts
Default Session object problem on Windows2000 server

Hello everyone,
I have very interesting and annoying problem in my IIS WEBClass application. This application works perfectly on my developer PC (Windows 2000 Professional and PWS on it) but start giving me some problems after I moved this application to the Windows 2000 Server to test it on the company Intranet. I am using Session object to keep the database connection inside the function CreateDBConnection():
Private Function CreateDBConnection() As Boolean
Dim strCnn As String
On Error GoTo EH

    CreateDBConnection = True

    'create the connection to the database
' Set Session("g_objConnManatee") = New ADODB.Connection 'D.M.08/28/03
    Set Session("g_objConnManatee") = Server.CreateObject("ADODB.Connection") 'D.M.08/28/03
    strCnn = "Provider=MSDASQL; DSN=ManateeWEB;"
    Session("g_objConnManatee").Open strCnn

    If Session("g_objConnManatee").State <> adStateOpen Then
        ' Return mouse pointer to normal.
        Screen.MousePointer = vbDefault
        CreateDBConnection = False
        Exit Function
    End If

    On Error GoTo 0
    Exit Function
EH:
    CreateDBConnection = False
End Function

But, on the line:
If Session("g_objConnManatee").State <> adStateOpen Then
I am getting the error: “Object required."
It means the Session object does not exist by some reason. I do not understand why??? The Session is part of ASP, which is part of Operating System. In my project I have a reference to the ASP.DLL, and in the Site's property the Session is checked.
Like I've said the application is working OK on my PC.

Are there any suggestions? Any help will be appreciated. It is very important to me.
Thanks in advance,
                     Dmitriy:(
 
Old September 2nd, 2003, 09:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am afraid I can not help you with your specific problem however I would like to suggest that you 'Never Place an OBJECT in a Session/Application Variable.'

The reason for this is that Session/Application variables are maintained on a specific thread (IIS is multithreaded) so you can only access the variable by using the same thread. If 10 people make the same request at the same time they will all have to wait for the thread to become available instead of using a different thread. This WILL slow down your web server.

For more information check out the Three Commandments for ASP Programming articles in the DevX web site available at http://archive.devx.com/upload/free/...icalasp4-2.asp

Regards
Owain Williams
 
Old September 2nd, 2003, 12:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jlick
Default

I don't agree that you should never plan ANY object in a session/application variable, but I do agree that you shouldn't place a connection object in a session/application variable.

What I would suggest doing is placing the connection string in the session object, and use createobject to get a connection. ADO will pool connections for the machine if the connection string is the EXACT same (including user & password). When you "create" the connection, if one is available in the pool, it will be used. Otherwise, you will get a new connection, which will be placed in the pool when you are done with it.



John R Lick
[email protected]
 
Old April 2nd, 2004, 07:29 AM
Registered User
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Dmitriy,

I had the same problem with loosing my session variables when I moved my asp application to the company intranet. The silly solution was that with newer browsers such as ie5.5, ie6 + a few patches, you cannot allow "_" (underscore) in your url. I removed it and, bang! - everything worked just fine and all the session object lived happliy ever after.

For more:
http://support.microsoft.com/default...b;EN-US;316112

sirW.

 
Old June 29th, 2004, 08:25 AM
xor xor is offline
Registered User
 
Join Date: Jun 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sirwinston,

I have had problems with CF and ASP pages related to use of underscore with session variables. Microsoft's article says that it´s possible to have problems with underscore in the server/domain name but it does not mention URL.

Last five years we have been putting underscore in filenames to organize developing. (includes => inc_db.cfm, inc_setvar.asp). Changing this now would make me review every sistem. Too big job.

Do you know if there is any workaround?

Tnx



 
Old July 4th, 2004, 08:22 AM
Authorized User
 
Join Date: May 2004
Posts: 83
Thanks: 0
Thanked 1 Time in 1 Post
Default

Your code appears to to be fine. I can't figure out a bug or anything of that sort. I am, however, not agreed to the approach you have used to keep connection to a database. I mean holding a connection object at the session scope. Here goes why...

As a matter of fact, a session is user specific. Keeping this in mind, if 20 clients connect to your application at the same time, there will be 20 connections opened up on the server hosting your app, 300 connections for 300 cleints and so on. You can see it would create a scalability nightmare for you as a connection is very precious resource.

A better approach would be to create a connection string at the application level, or at session level if it changes for each user, and open a connection on each page and then closing it as soon as you are finshed with it. This will surely solve your problem plus your application will scale to a greater degree.

Thanks

ejan
 
Old July 9th, 2004, 04:51 PM
Registered User
 
Join Date: Oct 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by sirwinston
 Hello Dmitriy,

I had the same problem with loosing my session variables when I moved my asp application to the company intranet. The silly solution was that with newer browsers such as ie5.5, ie6 + a few patches, you cannot allow "_" (underscore) in your url. I removed it and, bang! - everything worked just fine and all the session object lived happliy ever after.

For more:
http://support.microsoft.com/default...b;EN-US;316112

sirW.

Hi sirW,

I am just experiencing the same problem with pages losing session variables. I have used _ in the page URL, but the domain name does not contain _ at all. The MS article does not say whether the _ causes a problem if it is in the URL or the just the server name. Any help will be greatly appreciated.

Thanks
P
 
Old November 23rd, 2004, 02:42 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Dmitriy,

I am having the same problem.
Apparently upgrading to IIS 5, Win2K made it so that Session will receive simple variables (Integer, Double, etc.), but not the value of an ADODB recordset field, nor an instance of a class defined within the project.

For instance, if I make a class:

Option Explicit

Public V1 As String

called clsTest, and I create an instance of that class, trying to add it to the Session:

Public Sub Whatever()

    Dim ob As clsTest
    Set ob = New clsTest

    Set Session("Wagga") = ob

    . . .

in the watch window, the session item is still Variant/Empty.

I looked for your contact info, but there is none...
Have you found resolution to this problem?
Please contact me

Brian Wren
 
Old November 23rd, 2004, 05:32 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 121
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi Brian,
I've found solution to this problem:
I've created simple "DB Communication DLL", with just one class, let's name it "DBRelations". And include this DLL into my WEBClass project's reference list. I am calling functions from this DLL to Connect/Disconnect to database, to do all database related operations.
It works fast. If you need help, I can send this DLL project to you.
My email address: [email protected].
 -Dmitriy
 
Old December 6th, 2004, 02:57 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I believe the answer to this can be found in http://support.microsoft.com/?id=259725

It has to do with security, and the situation when debugging VB in the IDE.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Session object error ankur16 Apache Tomcat 0 May 23rd, 2006 04:43 AM
Session object keyvanjan Classic ASP Basics 1 January 25th, 2006 09:32 PM
session and cookie problem (empty session file) msincan BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 February 27th, 2005 05:31 PM
Session Object mcinar Classic ASP Basics 9 January 9th, 2005 05:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.