PRB: No Error On Invalid SetDefaultWorkspace in VB 4.0Last reviewed: April 16, 1996Article ID: Q129880 |
The information in this article applies to:
SYMPTOMSExecuting the SetDefaultWorkspace command with invalid parameters does not generate any error until a Database is opened or a Workspace is created. However, in Visual Basic version 3.0, this error is generated by the SetDefaultWorkspace statement. The SetDefaultWorkspace statement establishes the user ID and password for protected (security-enabled) Microsoft Jet databases. If you aren't using a protected database, this statement is ignored.
CAUSEIn Visual Basic version 3.0, the SetDefaultWorkspace command immediately attempted to verify the parameters passed to it for the current session. In Visual Basic 4.0, the Username and Password parameters passed to the SetDefaultWorkspace statement set properties on the DBEngine object. These properties are not applied until a Workspace is created or a Database is opened.
RESOLUTIONThe SetDefaultWorkspace statement is included in Visual Basic version 4.0 for compatibility with earlier versions. For Visual Basic version 4.0 applications, Microsoft recommends that you use the properties of the Workspace object instead. See the "Example Resolution" section near the end of this article for an example.
STATUSThis behavior is by design.
MORE INFORMATION
Steps to Reproduce BehaviorTo reproduce the SetDefaultWorkspace error, you must have a password protected Microsoft Access database. Visual Basic version 4.0 does not ship with a secure database. If you have Microsoft Access, you can add security to a database by opening the database and choosing Change Password from the Security menu.
In Visual Basic version 4.0, the error does not occur until you attempt to open a secure database. Replace the above code with the following. Note: to run this sample you must have the Microsoft DAO 2.5/3.0 Compatibility Library selected in the Tools References dialog.
Sub Form1_Load () Dim DB As Database SetDefaultWorkspace "Admin", "WrongPassword" Set DB = DBEngine.Workspaces.OpenDatabase("MyDB.MDB") ' Insert the name of a secured Microsoft Access database ' in the line above. ' VB4: Error occurs on OpenDatabase. End Sub Example ResolutionThe implication here is that you may need to move your error trapping code if you are currently trapping for errors on the SetDefaultWorkspace statement. To update your code to use the correct Microsoft DAO 3.0 syntax, replace the above version 4.0 example with the following:
Sub Form1_Click() Dim WS As WorkSpace Dim DB As Database DBEngine.DefaultUser = "Admin" DBEngine.DefaultPassword = "WrongPassword" Set WS = DBEngine.CreateWorkSpace("WS") Set DB = WS.Opendatabase("MyDB.MDB") ' Insert the name of a secured Microsoft Access database in the ' line above. End SubError trapping may have to be moved in order to accommodate the multiple Workspace capability of Visual Basic version 4.0. Error trapping should be set up to trap on the Opendatabase or CreateWorkspace methods.
|
Additional reference words: 4.00 vb4win vb4all
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |