DOCUMENT:Q177592 08-DEC-1997 [vbwin] TITLE :PRB: User Connection Object Connect Property Remains Populated PRODUCT :Microsoft Visual Basic for Windows PROD/VER:WINDOWS:5.0 OPER/SYS:WINDOWS KEYWORDS:vb5all ====================================================================== --------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual Basic Enterprise Edition for Windows, version 5.0 --------------------------------------------------------------------- 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. MORE INFORMATION ================ Steps to Reproduce Behavior --------------------------- 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 ------------------------------------ 1. Add two CommandButtons, Command1 and Command2, to Form1. Command1 establishes the connection; Command2 closes it Both display the Connect property in the debug window. 2. 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 3. 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. REFERENCES ========== For additional information about User Connection Designer, please see the following article in the Microsoft Knowledge Base: ARTICLE-ID: Q166281 TITLE : HOWTO: Create and Implement a UserConnection (c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Adrian Chiang, Microsoft Corporation ====================================================================== Keywords : vb5all Version : WINDOWS:5.0 Platform : WINDOWS Issue type : kbprb ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 1997.