Delphi下枚举局域网内SQL服务器以及数据库

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的扩展控件。经过测试可通过两种登录方式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值