The connection string required to connect to a database server may be created during design time or run time. There are circumstances under which you may want to store the connection string entirely outside the application, however. In those instances, Microsoft Data Link files are useful, as this article will explain.
Creating Data Link (UDL) Files in Delphi - Section 4: More undocumented routines in ADODB (Page 5 of 5 )
But that is not all, there a few more undocumented functions in the ADODB.pas unit which can help you avoid lengthy workarounds.
Procedure GetProviderNames(Names: Tstrings);
The GetProviderNames method can be used to fetch a list of all providers available.
Procedure GetDataLinkFiles (Names: Tstrings);
This function can be used to retrieve a list of filenames present in the DataLink folder (in my case the Data Link folder is in C:Program FilesCommon FilesSystemOle DB folder).
Function PromptDataSource(ParentHandle: THandle; InitialString: WideString): WideString;
This function can be used to bring up the DataLink property dialog box and let the user provide the Data Source name. The PromptDataSource function returns the selected Data Source name as WideString.
var ConxnStr:WideString; begin ConxnStr := PromptDataSource(Form1.Handle, ADOConnection1.ConnectionString); ..... end;
Function PromptDataLinkFile(ParentHandle: THandle; InitialFile: WideString): WideString;
This function returns the file name and its path as a string. It can be employed to let the user select the datalink to be used for connection.
var dlfStr:WideString; begin dlfStr:=PromptDataLinkFile(Form1.Handle,''); .... end;
Play around a little with these undocumented routines contained in the ADODB.pas unit file and you will find out how easy it is to create and manage ADO connections in your Delphi application without hard-coding the connection string or writing long and complicated codes.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.