Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO: How do I open the Data Link Properties dialog box.

Databases

ADO: How do I open the Data Link Properties dialog box.

by  2ffat  Posted    (Edited  )
Sometimes when using ADO (Active-X Data Object) you will need to know how to connect your ADO project to a database "on-the-fly," i.e. have the user set up the database connection information so your program is not locked into a single provider or database.

Microsoft has provided an API called IDBPromptInitialize::promptDataSource. This API opens the Data Link Property dialog box which allows the user to select such items as the data provider, database, user, etc. You can search MSDN for more information on this.

There is an also undocumented VCL that encapsulates this API. Called PromptDataSource, it only needs your app's handle and a widestring. It returns a widestring with the connection information.
Code:
WideString PromptDataSource(int Handle, WideString ConnectionString);

Your app's handle can be found by (int)Application->Handle or (int)MyForm->Handle. The connection string can be a blank ("") or an actual connection string. If the passed connection string is valid, the called dialog box will show the data object as the default.

To use this function, you will need to include ADODB.hpp in your app's header file. You can then use a button on your app to call the VCL.
Code:
void __fastcall TMyForm::DialogButtonClick(TObject *Sender)
{
    WideString WCEStr = Edit1->Text;
    WideString WResult = PromptDataSource((int)Application->Handle, WCEStr);
    Edit1->Text = WResult;
}
//---------------------------------------------------------------------------

In the above example, the VCL takes the app's handle and a string from an edit box. The returned string is then placed back into the edit box. This allows any subsequent calls to the VCL to use the same connection info. [color red]NOTE:[/color]Any password entered into the dialog box can be passed back to the calling app and is available as plain text in this example.

Your ADO component can then use the returned widestring as its connection string.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top