Visual Basic Q&A

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries Tagged ‘client’

PRB: RDO/Jet: Run-Time Error 40069; Client Cursor Error 11 or 12

Symptoms
When you run a SELECT statement against the Microsoft Jet ODBC driver usingRDO and the client batch cursor engine, you receive one of the followingtwo error messages:

Run-time error 40069
Client Cursor: 11 – No update tables are specified
-or-

Run-time error ‘40069′:
Client Cursor: 12 – No key columns are specified for the update table
Resolution
When using the client batch cursor engine, and opening a static resultset,you must use the same case as in the table when typing field names into theSELECT clause of the SQL statement. This applies to the primary key fieldand any BLOB (Binary Long Object) columns–LongVarChar and LongVarBinary.

How To Troubleshoot Run-time Error ‘70′ in DCOM Applications

Symptoms
Attempting to access a DCOM Server from a remote client application sometimes results in the following error:

Run-time error ‘70′:
Permission Denied
This article describes the most common scenarios in which this error is raised.
Resolution
Run-time error ‘70′ is typically the result of a security or permissions issue. The following is a list of possible causes of run-time error 70 but is by no means a complete or definitive list.
DCOM Is Not Enabled If the Server machine does not have DCOM enabled, client machines will receive run-time error 70 when attempting to access the server. This scenario applies to Windows 2000, Windows NT, Windows 95, Windows 98, and Windows Millennium Edition (Me) servers:
On the Server machine, run DCOM Config (DCOMCNFG.EXE). Choose the Default Properties tab. Ensure that Enable Distributed COM on this computer is checked. This value is stored in the Windows Registry at the following location:
HKEY_LOCAL_MACHINE\Software\Microsoft\OLE
The Client User Does Not Have Sufficient Permissions If the client user does not have the correct permissions, access to the DCOM Server can be denied. There are several steps to take in order to ensure your client has valid privileges.
If the Server is Windows 95, Windows 98, or Windows Me:
Run DCOM Config. Select the DCOM Server application from the list of available applications. Select the Properties button, or double-click the DCOM Server application in the list. Test the server with “Default Access Permissions.”
If run-time error ‘70′ still occurs, the default access permissions are restricting your user. If this is the case, then modify the Default Access Permissions from the Default Security tab in DCOM Config. Grant the client user access permissions.
If run-time error ‘70′ does not occur running with default access permissions, it is likely that the custom access permissions are restricting your client from accessing the DCOM Server. Choose custom access permissions and select the Edit button. Grant the client user access permissions. If the Server is Windows NT or Windows 2000:
Run DCOM Config. Select the DCOM Server application from the list of available applications. Select the Properties button, or double-click the DCOM Server application in the list. Test the server with “Default Access Permissions,” “Default Launch Permissions,” and “Custom Configuration Permissions.”
If run-time error ‘70′ still occurs, it is likely that the default access permissions are restricting your user. If this is the case, modify the Default Access Permissions from the Default Security tab in DCOM Config.
If run-time error ‘70′ does not occur, it is likely that the custom access permissions are restricting your client from accessing the DCOM Server. Choose to use Custom access permissions and choose the Edit button. Grant the client user account access permissions, or grant a group the client user belongs to access permissions. For more information regarding security groups on Windows NT see the table to follow.
There are several group accounts you will find when you configure users and groups on Windows NT and Windows 2000. The following list is a summary of who belongs to each group:

GroupDescription————————————————————————–InteractiveIncludes all users who log onto a Windows NT orWindows 2000 system locally (at the console). Itdoes not include users who connect to NTresources across a network or are started as aserver.NetworkIncludes all users who connect to Windows NT orWindows 2000 resources across a network. It doesnot include those who connect through aninteractive logon.Creator/OwnerThe Creator/Owner group is created for eachsharable resource in the Windows NT orWindows 2000 system. Its membership is the set ofusers who either create a resource (such as afile) and who take ownership of them.EveryoneAll users who access the system, whether locally,remotely, or across the network.SystemThe local operating system.
The above list includes the group accounts which are intrinsic to Windows NT and Windows 2000 systems. Your particular network may include more groups from which you may choose. In order to determine the membership of each custom group account, you must contact your network administrator.

The DCOM Server Raises Events to the Client If your DCOM server component raises events that are handled by the client application, you must configure DCOM security on the client computer to allow access, and you must configure DCOM security on the server computer. This allows the server to make callbacks to the client, so the event can be raised. If you do not configure DCOM security in this way, error 70 is generated whenever the client application calls the server. This results in an event being raised back to the client. If the server application does not raise events, you do not have to configure DCOM security on the client computers.
If the client computer is running Windows 95, Windows 98, or Windows Me, follow these steps:
Run DCOM Config (DCOMCNFG.exe). Click the Default Security tab. Click the Edit Default button. Click the Add button. Click to select The World, and then click the Grant Access button to grant permissions. Click Ok to close the Add Access Permissions dialog box. Click Ok to close the Access Permissions dialog box. Click Ok to close the DCOM Config Properties dialog box. Test the application again.
The client application successfully handles the event.
If the client computer is running Windows NT orWindows 2000, follow these steps:
Run DCOM Config (DCOMCNFG.exe).Click the Default Security tab. Click the Edit Default button. Click the Add button.Click to select the Everyone account, and then click to select Allow Access in the Type of Access box. Click Ok. Click Ok again to close the Registry Values Permission dialog box. Click Ok to close the DCOM Config Properties dialog box. Test the application again.
The client application successfully handles the event.
Attempting to Access DCOM Server Across Non-Trusted Domains If your DCOM Server resides in one Windows NT or Windows 2000 domain, and your client logs on to a second Windows NT or Windows 2000 domain that is not “trusted” by the first, you will receive run-time error ‘70′ when attempting to access the DCOM Server.

How To Create a DCOM Client/Server Application by Using Visual Basic

Symptoms
This article shows you how to create, package, and deploy a Distributed Component Object Model (DCOM) client/server application by using Visual Basic. To create a DCOM client/server application, you need the Enterprise Edition of Visual Basic. Microsoft assumes that the reader is already familiar with creating client/server applications that run on the same computer.
Resolution
You do not need to change your code to enable a client application to instantiate a remote server by using DCOM. The difference is the way in which you package and deploy the client. In addition, there are some security settings you need to make after the client and the server are installed. You can make these settings by using an utility called Dcomcnfg.
The following steps show you how to distribute and configure a simple client/server application. Name the server DCOMDemo_Svr, and name the client DCOMDemo_Cli. Create a separate folder for each of them. For the purpose of this article, call these folders c:\DCOMDemo\Server and c:\DCOMDemo\Client.
Create the ServerStart a new Visual Basic Project. On the New Project dialog box, select ActiveX EXE, and then click Open. Class1 is created by default. Add the following code to the Class1 module:

Public Function ServerTime() As StringServerTime = TimeEnd Function On the Project menu, click the Project Properties option, and then select the General tab.In the Project Name field, type in DCOMDemo_Svr.On the Project Description field, type in DCOMDemo_Svr – Server. Check the Unattended Execution option.
NOTE: This option should always be checked in servers that don’t have any UI to assure that no dialog boxes of any type are displayed while the server is running. If you have any type of user interaction while your server is running under an identity that is not the Interactive User, your server may appear to hang.Select the Component tab, and check the Remote Server Files option.
NOTE: Checking this option makes the Visual Basic compiler generate the VBR and TLB files needed for packaging the client applications that use this server. These files contain registry entries that need to be included on the client computer.Close the Project Properties dialog box.On the File menu, select Save As, and then save this project to the c:\DCOMDemo\Server folder.On the File menu, select Make DCOMDemo_Svr and compile the server.On the Project menu, select the Project Properties option, and then select the Component tab.On the Component tab, select Version Compatibility, select the Binary Compatibility option, and then make the project binary compatible with the server’s executable file you just created (DCOMDemo_Svr.exe). By selecting this option you are assuring that all GUIDs are kept the same if you recompile the server.
Create the ClientOn the File menu, select the New Project option, select Standard EXE, and then click OK. Form1 is created by default.On the Project menu, click the Project Properties option, and then select the General tab.In the Project Name field, type in DCOMDemo_Cli. In the Project Description field, type in DCOMDemo_Cli Project – Client.On the Project menu, select References. From the list of available references, select DCOMDemo_Svr – Server. Place a command button on Form1, and change the button’s caption to Run.Place the following code in the button’s click event:

Dim MyObj As DCOMDemo_Svr.Class1On Error GoTo err1Set MyObj = CreateObject(“DCOMDemo_Svr.Class1″)MsgBox “Server Time=” & MyObj.ServerTime & “Client Time=” & TimeExit Suberr1:MsgBox “Connection failed: Error ” & Err.Number & ” – ” & Err.Description On the File menu, select Save As, and then save the project to the client’s folder c:\DCOMDemo\Client. Press the F5 key to run the client in the IDE and test it out.On the File menu, select Make DCOMDemo_Cli to compile the client, and then close Visual Basic.
Package the ServerUse the Package and Deployment Wizard to package your server for distribution as usual. The server is instantiated by a remote client using DCOM. While creating the package for your server, you get a dialog box asking you if this server will be used as a Remote Automation server and if you want to include support files for this purpose. Just click the No button, because DCOM is not Remote Automation. Remote Automation is an older technology that was replaced by DCOM.
Package the ClientWhen packaging the client there are some specific steps that need to be taken, considering that the server does not run on the same computer as the client. The changes made to the client’s package assure that just the type library (.tlb file) is installed and some additional registry entries are included instead of the server’s executable, which is not necessary on the client’s computer because it’s not going to run there.
Package the client by using the following steps:Start Package and Deployment Wizard, and then select the Client’s project.Click the Package button. In the Package Type dialog box, select Standard Setup Package, and then click Next.In the Package Folder dialog box, select the folder to store the package, and then click Next. In this case, it is c:\DCOMDemo\Client\Package.
NOTE: You may get a dialog box saying that there is no dependency information for the server. Click OK because this server doesn’t have any dependencies.
You should now be in the Included Files dialog box. Deselect the server’s executable file, DCOMDemo_Svr.exe, because you do note want to distribute the server’s executable, and then click the Add button. Change the Files of Type combo box to Remote Server Files (*.vbr).Point to the folder where you have your Server’s project (in this case c:\DCOMDemo\Server), and select the related VBR file, DCOMDemo_Svr.VBR. Click Open, and the Add File dialog box closes. Notice that two files are included, DCOMDemo_Svr.VBR and DCOMDemo_Svr.TLB. Click the Next button.
NOTE: In the Remote Servers dialog box you can define the name of the computer (Net Address) where the server is running. Usually you keep this field blank because you may not know in advance where the server will be installed. If you keep it blank, you are prompted for it when you install the client. For this sample, keep it blank.Click Next to proceed. You can now proceed with the standard procedures for Package and Deployment Wizard. In this case, just click Next to all remaining dialog boxes
Install the ServerInstall the server on the computer on which you would like to run it, using the distribution package you created earlier. If you want to use your development computer to run the server, you don’t need to install it because Visual Basic makes the registration for you when it compiles the server.
Install the ClientInstall the Client on the computer on which you would like to run it, using the distribution package you created earlier. Because this client uses a DCOM server and you left the actual location of the server blank when you created the distribution package, you now need to provide this location. When Setup prompts you for this location, provide the name of the computer where you installed the server.
Set the Server’s SecurityIf you installed the server on a Microsoft Windows NT or Microsoft Windows 2000 computer, you need to configure security for it. Do this by using Dcomcnfg, as shown in the following steps, which assume that both client and server computers are part of a domain, and the user logged on to the client computer is logged on as a domain user. The suggested settings are just one possible configuration. They are very generic and give wide access to the server. Remember that this is just an example. When you deploy your real applications, and security is a concern for your environment, you should select more restrictive options. Also, if the computer you are using to test this example server is used to run other servers, make a note of the current settings before you make the following changes, and return to the original settings as soon as you are done with your tests.On the server computer, click the Start button, and then select Run. In the Run dialog box, type Dcomcnfg, and then click OK. You need to have Administrator rights to be able to run Dcomcnfg.Select the Default Properties tab, and verify that Enable Distributed COM on this computer is checked.Set the Default Authentication Level to Connect, and set the Default Impersonation Level to Identify.Select the Default Security tab.Click the Edit Default button in the Default Access Permissions panel.Verify that Everyone and System are included in the list with Allow Access rights. If they are not, you can use the Add button to add them to the list. Click OK when the list is complete.Click the Edit Default button in the Default Launch Permissions panel.Verify that Everyone and System are included in the list with Allow Launch permissions. If they are not, use the Add button to add them to the list. Click OK when the list is complete.Select the Applications tab, highlight your server, DCOMDemo_Svr.Class1, and then click the Properties button. Select the General tab, set the Authentication Level to Default, and then select the Location tab.The only option that is checked should be Run application on this computer.Select the Security tab and verify that the Use default access permissions and the Use default launch permissions options are checked.Select the Identity tab, check The launching user option, click OK to close the Server’s Properties dialog box, and then click OK again to close Dcomcnfg.As you can see, the test server uses all of the default settings. When deploying your own servers, you should define settings specific to your application. All custom settings take precedence over the default ones.
You are now ready to test your server. On the client computer, launch the client, and then click the Run button. You should see a message box indicating the server’s time. If you are unable to test this sample successfully, please see the troubleshooting article, Q269330, listed in the “References” section.

BUG: Crash When Closing Application That Uses ActiveX DLL

Symptoms
Using Visual Basic, you create one or more ActiveX DLLs and a Standard EXE(client) application to use the DLLs. The client application runs asexpected within the Visual Basic (IDE) environment. However, when youcompile and run the client application as an EXE, the application producesone of the following errors upon closing:

<project name> caused an invalid page fault inmodule MSVBVM50.DLL at 0137:0f059b41.
-or-

Exception: access violation (0xc0000005), Address: 0×0f059b41
Resolution
This problem can occur when the objects you create in the DLL are notclosed properly by the client application due to a circular reference. Acircular reference occurs, for instance, in the following scenario:
A client application instantiates an object in the ActiveX DLL: theParent object. The Parent object creates another object in the DLL: theChild object. The Parent object sets a property in the Child object thatallows the Child object to have a reference to the Parent object.
This creates a circular reference between the Parent and Child objects.When the client application that created the Parent object sets its objectvariable to Nothing, the Parent object does not terminate because the Childobject maintains a reference to the Parent object. The MORE INFORMATIONsection below describes a specific case for this problem and provides asolution, which is to remove the Child’s reference to the Parent objectbefore closing the Parent object.