How To: Prompt the user for database properties: User, Password, Version
When you create a database connection in ArcCatalog, you are asked whether you want to save the connection properties. If the properties are not saved, you are prompted to provide connection properties whenever you make a database connection. This article outlines how to force the same prompt programmatically.
- Start ArcMap.
- Create a new UIButtonControl: How To: Create a new UIButtonControl
Note: For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
- Right-click the UIButtonControl and select View Source.
- Copy this code into the UIButtonControl's click event.
Code: Dim pWF As IWorkspaceFactory Dim pPropSet As IPropertySet Set pWF = New SdeWorkspaceFactory Set pPropSet = New PropertySet pPropSet.SetProperty "SERVER", "myserver" pPropSet.SetProperty "INSTANCE", "nnnn" ' ***** Omit references to SetProperty when you want to prompt for user input 'pPropSet.SetProperty "USER", "sde" 'pPropSet.SetProperty "PASSWORD", "sde" 'pPropSet.SetProperty "DATABASE", "db" 'SQL Server and Informix only 'pPropSet.SetProperty "VERSION", "SDE.DEFAULT" pWF.Open pPropSet, 0 MsgBox "Finished"
- Modify the code for your RDBMS. Click the UIButtonControl to test.
Note: Experiment with the code. Uncomment those lines of code which set the properties for which you don't wish to prompt the user. For example, to hard-code the version yet still force a prompt for User and Password, then uncomment the SetProperty for VERSION.