Click here to Skip to main content
14,447,082 members

How to connect SQL server dynamically to delphi

rezki_z asked:

Open original thread
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;

type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
s : string;
begin
if adoconnection1.connected then
begin
adoconnection1.Connected:=false;
end else
begin
s := adoconnection1.ConnectionString;
s := adodb.PromptDataSource(self.Handle, s);
adoconnection1.ConnectionString := s;
try
adoconnection1.connected:=true;
except
end;
end;
Edit1.text := s;
end;
end.

What I have tried:

I have this code for access database i want the same code for sql server thanks
Tags: Delphi

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100