Mega Code Archive

 
Categories / Delphi / ADO Database
 

How To Building Connection String At Run Time For Any DataBases

Title: How To Building Connection String At Run-Time For Any DataBases Question: Hi Have you Ever Worked with "ConnectionString" Property of ADO Components in Delphi? When you click on this Property ,a window appear with the following Choice for Building Connection String: 1)Use DataLink File...............Browse... 2)Use Connection String...........Build.... Then when you Click on the build Button another Window ("Data-Link-Properties" Dialog) Appear and let you to Create your own Connection String.Some time back i wanted to Integrate this Dialog to my Application to give user ability to Build Connection-String at Run-Time,But I didn't know how to do this.Finally i Found out this Trick and Now i want to Share it With You: Answer: The Solution is easy,All you have to do is Invoking one of the ADODB Unit'Function Called "PromptDataSource" .it has the following Syntax: function PromptDataSource(ParentHandle: THandle; InitialString: WideString): WideString; what is strange for me is that ,there isn't any Documentation for this Function in Delphi !!! By the way the following is a simple example to use this Function.Suppose we have a Memo on the form,where User can Edit the Connection String as He/She want.Don't Forget to Add "ADODB" Unit to the Uses Clause //------------------------------------------------------------- procedure TForm1.Button1Click(Sender: TObject); var ConnectionString: String; begin ConnectionString := PromptDataSource(0, Memo1.Text); if ConnectionString '' then begin Memo1.Text := ConnectionString end; end; //------------------------------------------------------------- That's all.After Execution reach to this function,The Mentioned Window,"("Data-Link-Properties" Dialog) appear. I'm Glad to Read your Comments. :-) With Best Wishes.