Developer

Troubleshooting Access connections and creating shortcuts with VB

Two questions are tackled: What do you do with a database that says it has more users than it really has, and how do you programmatically create a shortcut?


This week's Visual Basic Q&A is a special two-for-one, extra-value-meal edition. First, we help a member who’s running out of connections to his Access database way before he hits the limit of 255 users. Then, we look at a simple way to add shortcuts to a user's desktop.

What's wrong with my database?
Q: Here's a good one for you. Nobody has been able to answer this one for me yet. We have multiple users with Win95 and Win98, an Access97 database that resides on a Novell 4.11 server, and an app written in VB 6.0 Enterprise using ADO. Every so often, my users get the error message "Too Many Active Users," usually followed by an "OLE Automation Error" that terminates the program.

—Mark Korolevich


A: Every now and then, we get questions that are just too specialized to answer in this column. I initially thought Mark's question might be one of those, and so it sat in our inbox for some time before I decided to take another look at it. The Novell aspect stuck in my head: I remembered something about a problem revolving around Novell and Access from one of my "past lives."

As it turns out, Novell itself is causing the problem in this case. According to this Microsoft Knowledge Base article, the problem is that the Novell client does not release the locks on the database file, causing the LDB file, which contains locking information for the database, to "fill up" with active users that are no longer connected to the database. When the LDB file's total number of users hits 255, you get the "Too Many Active Users" error from the Jet driver, or a longer error, if you happen to be using the ODBC driver. Microsoft recommends installing the Novell 3.2 client, available from Novell's support Web site, to correct the problem. Good luck, Mark.

How do I create a shortcut on the desktop?
Q: Is there a way to programmatically create a Windows shortcut on a user's desktop with a specific Target Path, Start In Path, Icon, etc.?

—Steven Collazo


A: Yes, there's actually a pretty easy way to do this with the Windows Scripting Host (WSH). Since this is Visual Basic Q&A and not VBScript Q&A, I'll assume you want some example VB code, not script, showing how this is done. The code appears in Listing A. Make sure to run it from a project with a reference to Windows Scripting Host Object Model (wshom.ocx). The result of running this sample code is a new shortcut on the desktop that displays the file C:\WINNT\directx.log in Notepad. Figure A shows the properties page for the new shortcut.

Figure A
Why, yes, it does.


To create a shortcut, create a new instance of WSH's IWshShortcut_Class class using the IWshShell_Class.NewShortcut method, specifying the path and name of your new shortcut. If you use the name of an existing shortcut, your new shortcut will replace it. The IWshShortcut_Class has the following properties:
  • ·        Description: Any text specified will appear in the Comment section of the new shortcut's properties dialog.
  • ·        IconLocation: The path and filename of the icon the shortcut should use (If specifying an EXE file, be sure to include an index identifier; zero [0] usually works fine.)
  • ·        TargetLocation: The full path and filename of the shortcut’s target
  • ·        WorkingDirectory: The path to use as a working directory for the shortcut's target
  • ·        Arguments: Allows you to include any command-line arguments that should be passed to the shortcut's target
  • ·        WindowStyle: Specifies the target's window style (Allowed values here are 1 for normal, 3 for maximized, and 7 for minimized.)

After setting any desired properties for your new shortcut, call the Save method to have it created. Remember that shortcut filenames must always have an .lnk extension.

 

Editor's Picks