Microsoft KB Archive/177592

= PRB: User Connection Object Connect Property Remains Populated =

Article ID: 177592

Article Last Modified on 1/8/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q177592



SYMPTOMS
When a UserConnection object is declared at the global level, the userid and password stored in the Connect property remains populated after the connection is closed.



RESOLUTION
To make sure the userid and password in Connect property is cleared after closing the connection, you can set the user connection object to Nothing right after closing the connection, such as:

uc.close

SET uc = Nothing

You could also store the initial value of the Connect property to a variable, and replace the Connect property with that value after the connection is closed, such as the following:

Dim myConnect As String

myConnect = uc.Connect

uc.EstablishConnection

uc.Close

uc.Connect = myConnect



STATUS
Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



Task 1: Create the UserConnection

 * 1) Start a new project in Visual Basic and choose "Standard EXE." Form1 is created by default.
 * 2) From the Project menu, select Components, select the Designers tab, and then place a check next to Microsoft UserConnection.
 * 3) From the Project menu, select Add ActiveX Designer, and then select Microsoft UserConnection. This will bring up a dialog titled "UserConnection1 Properties."
 * 4) On the Connection tab, select either a DSN or DSN-less connection and fill in the appropriate information. On the Authentication tab, leave User Name and Password blank. At ODBC Prompt Behavior dropdown box, choose "Only when needed."
 * 5) Click OK to save this information and return to the Designer window.

Task 21: Build the Visual Basic Code
 Add two CommandButtons, Command1 and Command2, to Form1. Command1 establishes the connection; Command2 closes it Both display the Connect property in the debug window.  Paste the following code in the General Declaration section of Form1: ' *** To workaround the problem: ' *** Uncomment the 2 lines of VB code to re-set ' *** Connect property using variable myConnect ' ***

Dim uc As New UserConnection1 Dim myConnect As String

Private Sub Command1_Click ' myConnect = uc.Connect Debug.Print uc.Connect uc.EstablishConnection End Sub

Private Sub Command2_Click uc.Close ' uc.Connect = myConnect Debug.Print uc.Connect End Sub

Private Sub Form_Load Command1.Caption = "Establish Connection" Command2.Caption = "Close Connection" End Sub

Private Sub Form_Unload(Cancel As Integer) Set uc = Nothing End Sub  Press F5 key to start the program.

NOTE: Because the userid and password remain populated in the Connect property after closing the connection, you are only prompted once for the authentication information after the first connection is established.

