如何测试使用ADO的SQL Server连接

TestLoginADO.iss
 
 
; Inno Setup 5.0.8

[Setup]
AppName=TestLoginADO
AppVerName=TestLoginADO
Uninstallable=false
UpdateUninstallLogAppName=false
DisableDirPage=false
DisableProgramGroupPage=true
DefaultDirName={pf}\TestLoginADO
DisableStartupPrompt=true
CreateAppDir=false
OutputBaseFilename=TestLoginADO
AllowUNCPath=false

[Code]
function TestADOConnection( server, username, password: String ) : Boolean;
var
  adocon: Variant;
  adostr: String;
begin
  Result := false;
   adostr := 'Provider=SQLOLEDB.1;Persist Security Info=False;' +
    'User ID='+ username +';Data Source=' + server +
    ';Password=' + password;
  try
    adocon := CreateOleObject('ADODB.Connection');
  except
    RaiseException('Please install ADO (MDAC) first.'#13#13+
          '(Error ''' + GetExceptionMessage + ''' occurred)');
  end;
  try
    adocon.Open( adostr );
  except
    RaiseException('Error Connecting.'#13#13'(Error ''' + GetExceptionMessage + ''' occurred)');
  end;
  Result := true;
end;

#include "TestLoginADO.isd"
procedure InitializeWizard();
begin
 LoginSQL_CreatePage(wpWelcome);
end;
 
===============================================
TestLoginADO.isd
 
  [CustomMessages]
  LoginSQLCaption=LoginSQL Caption
  LoginSQLDescription=LoginSQL description
  [Code]
  var
    lbUsername: TLabel;
    lbServer: TLabel;
    lbPassword: TLabel;
    edUsername: TEdit;
    edServer: TEdit;
    edPassword: TEdit;
  procedure LoginSQL_Activate(Page: TWizardPage);
  begin
  end;
  function LoginSQL_ShouldSkipPage(Page: TWizardPage): Boolean;
  begin
    Result := False;
  end;
  function LoginSQL_BackButtonClick(Page: TWizardPage): Boolean;
  begin
    Result := True;
  end;
  function LoginSQL_NextButtonClick(Page: TWizardPage): Boolean;
  begin
    Result := TestADOConnection( edServer.Text, edUsername.Text, edPassword.Text  );
  end;
  procedure LoginSQL_CancelButtonClick(Page: TWizardPage; var Cancel, Confirm: Boolean);
  begin
  end;
  function LoginSQL_CreatePage(PreviousPageId: Integer): Integer;
  var
    Page: TWizardPage;
  begin
    Page := CreateCustomPage(
      PreviousPageId,
      ExpandConstant('{cm:LoginSQLCaption}'),
      ExpandConstant('{cm:LoginSQLDescription}')
    );
    { lbUsername }
    lbUsername := TLabel.Create(Page);
    with lbUsername do
    begin
      Parent := Page.Surface;
      Left := ScaleX(32);
      Top := ScaleY(80);
      Width := ScaleX(48);
      Height := ScaleY(13);
      Caption := 'Username';
      FocusControl := edUsername;
    end;
    { lbServer }
    lbServer := TLabel.Create(Page);
    with lbServer do
    begin
      Parent := Page.Surface;
      Left := ScaleX(32);
      Top := ScaleY(16);
      Width := ScaleX(32);
      Height := ScaleY(13);
      Caption := 'Server';
      FocusControl := edServer;
    end;
    { lbPassword }
    lbPassword := TLabel.Create(Page);
    with lbPassword do
    begin
      Parent := Page.Surface;
      Left := ScaleX(32);
      Top := ScaleY(144);
      Width := ScaleX(46);
      Height := ScaleY(13);
      Caption := 'Password';
      FocusControl := edPassword;
    end;
    { edUsername }
    edUsername := TEdit.Create(Page);
    with edUsername do
    begin
      Parent := Page.Surface;
      Left := ScaleX(32);
      Top := ScaleY(96);
      Width := ScaleX(325);
      Height := ScaleY(21);
      AutoSize := False;
      TabOrder := 1;
      Text := 'sa';
    end;
    { edServer }
    edServer := TEdit.Create(Page);
    with edServer do
    begin
      Parent := Page.Surface;
      Left := ScaleX(32);
      Top := ScaleY(32);
      Width := ScaleX(329);
      Height := ScaleY(21);
      AutoSize := False;
      TabOrder := 0;
      Text := 'localhost';
    end;
    { edPassword }
    edPassword := TEdit.Create(Page);
    with edPassword do
    begin
      Parent := Page.Surface;
      Left := ScaleX(32);
      Top := ScaleY(160);
      Width := ScaleX(325);
      Height := ScaleY(21);
      AutoSize := False;
      PasswordChar := '*';
      TabOrder := 2;
    end;

    with Page do
    begin
      OnActivate := @LoginSQL_Activate;
      OnShouldSkipPage := @LoginSQL_ShouldSkipPage;
      OnBackButtonClick := @LoginSQL_BackButtonClick;
      OnNextButtonClick := @LoginSQL_NextButtonClick;
      OnCancelButtonClick := @LoginSQL_CancelButtonClick;
    end;
    Result := Page.ID;
  end;

你可能感兴趣的:(数据库,职场,休闲,如何测试使用ADO的SQL,Server连接)