枚举SQL服务器及数据库

作者在 2007-07-06 19:30:00 发布以下内容
unit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, dxCntner, dxEditor, dxExEdtr, dxEdLib, StdCtrls,
ComCtrls,ComObj, Buttons;
type
TfrmMain = class(TForm)
Panel1: TPanel;
Bevel1: TBevel;
Bevel2: TBevel;
Bevel4: TBevel;
Label1: TLabel;
HostName: TdxPickEdit;
Label2: TLabel;
DataBaseName: TdxPickEdit;
GroupBox1: TGroupBox;
Label3: TLabel;
dxEdit1: TdxEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Label4: TLabel;
Label5: TLabel;
UserID: TdxEdit;
UserPass: TdxEdit;
Label6: TLabel;
PassLogin: TRadioButton;
NtLogin: TRadioButton;
procedure HostNameDropDown(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure DataBaseNameDropDown(Sender: TObject);
procedure NtLoginClick(Sender: TObject);
procedure PassLoginClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
procedure TfrmMain.HostNameDropDown(Sender: TObject);
var
SQLServer:Variant;
ServerList:Variant;
i,nServers:integer;
begin
if HostName.Items.Count<1 then
begin
HostName.Items.Clear;
SQLServer:=CreateOleObject('SQLDMO.Application');
ServerList:=SQLServer.ListAvailableSQLServers;
nServers:=ServerList.Count;
for i:=0 to nservers-1 do
HostName.Items.Add(ServerList.Item(i));
SQLServer:=NULL;
serverList:=NULL;

end;
end;
procedure TfrmMain.BitBtn2Click(Sender: TObject);
begin
Close;
end;
procedure TfrmMain.DataBaseNameDropDown(Sender: TObject);
var
SQLServer:Variant;
Server:Variant;
db:Variant;
i,j:integer;
begin
SQLServer:=CreateOleObject('SQLDMO.Application');
Server:=CreateOleObject('SQLDMO.SQLServer');
if NtLogin.Checked then
begin
Server.LoginSecure:=True;
//设置为WINDOWS登录模式
Server.Connect(HostName.Text);
Server.IntegratedSecurity.SecurityMode:=1;
Server.DisConnect;
Server.Stop;
while Server.Status<>3 do
begin
end;
Server.Start(True,HostName.Text);
end
else
begin
Server.LoginSecure:=True;
//设置为混合登录模式
Server.Connect(HostName.Text);
Server.IntegratedSecurity.SecurityMode:=2;
Server.DisConnect;
Server.Stop;
while Server.Status<>3 do
begin
end;
Server.Start(True,HostName.Text);
end;
db:=Server.DataBases;
i:=db.Count;
DataBaseName.Items.Clear;
for j:=1 to i do
DataBaseName.Items.Add(db.item(j).name);
Server:=NULL;
SQLServer:=NULL;
db:=NULL;
end;
procedure TfrmMain.NtLoginClick(Sender: TObject);
begin
if Ntlogin.Checked=True then
begin
UserID.Enabled:=False;
UserPass.Enabled:=False;
end;
end;
procedure TfrmMain.PassLoginClick(Sender: TObject);
begin
if PassLogin.Checked=True then
begin
UserID.Enabled:=True;
UserPass.Enabled:=True;
end;
end;
end.
程序中使用的控件为Developer Express Inc的扩展控件。经过测试可通过两种登录方式
软件技术资料摘录 | 阅读 1195 次
文章评论,共0条
游客请输入验证码