Bilgisyara MS Sql Server Yüklenip Yüklenmediğini Kontrol Etme Gönderen: dynamo Tarih: 02 July 2007 09:10:26
Bilgisyarda sql server kurulu mu, kurulu ise instance name nedir?
yüklü sql server listesi registryde "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server" anahtarı altında "InstalledInstances" değerinde tutulmaktadır.sql server 2005'te instance name'ler "SQLEXPRESS" ile başlıyor.

sql server yüklü mü:
[code]
//uses Registry
function SqlInstalled: boolean;
var path: string;
reg: TRegistry;
begin
result := true;
reg := TRegistry.Create;
reg.RootKey := HKEY_LOCAL_MACHINE;
if reg.OpenKey('SOFTWARE\Microsoft\Microsoft SQL Server\80\Tools\ClientSetup', false) = false then
result:=false;
reg.CloseKey;
reg.Free;
end;
[/code]
yüklü sql server listesi:
[code]
//Yuklu olan SQL Server isimleri (instancename)
//uses Registry
procedure SQLInstances(Instances: TStrings);
procedure GetDoubleNullStrings(Buf: Pointer; Strings: TStrings);
var
P: PChar;
begin
Strings.Clear;
P := Buf;
while P^ <> #0 do
begin
Strings.Add(P);
Inc(P, StrLen(P) + 1);
end;
end;
var
reg : TRegistry;
Buf : Pointer;
BufSize: Integer;
begin
if Instances = nil then
Instances := TStringList.Create;
reg := TRegistry.Create;
try
reg.RootKey := HKEY_LOCAL_MACHINE;
If (reg.OpenKey('\SOFTWARE\Microsoft\Microsoft SQL Server',False)) and (reg.ValueExists('InstalledInstances')) then
begin
BufSize := reg.GetDataSize('InstalledInstances');
GetMem(Buf, BufSize);
reg.ReadBinaryData('InstalledInstances', Buf^, BufSize);
try
GetDoubleNullStrings(Buf, Instances);
finally
FreeMem(Buf);
end;
end
else begin//sql server is not installed
end;
finally
reg.Free;
end;
end;
[/code]
[code]
procedure TForm1.Button1Click(Sender: TObject);
begin
//sql server yuklu mu
if SqlInstalled then
begin
Application.MessageBox('sql server yüklü .','sql server kontrol',mb_ok+mb_iconinformation) ;
//yuklu sql server listesi
ListBox1.Clear;
SQLInstances(listbox1.items);
end
else
Application.MessageBox('sql server yüklü değil.yüklemek istiyor musunuz...?','sql server kontrol',mb_yesno+mb_iconinformation);
end;
[/code]
örnek uygulama ekte