gpt4 book ai didi

inno-setup - Inno 设置 : connect to sql using windows authentication

转载 作者:行者123 更新时间:2023-12-04 05:30:11 25 4
gpt4 key购买 nike

谁能告诉我如何通过 inno 使用 Windows 身份验证连接到 SQL 2008?目前我正在使用 ado connection to connect to SQL从 inno 开始,用户也需要 Windows 身份验证选项。请建议。

最佳答案

当我们谈论您在问题中链接的示例并包含以下内容之一时,从您的连接字符串( User IdPassword )中删除凭据属性就足够了:

  • Integrated Security=SSPI;
  • Trusted_Connection=True;

  • 此答案仅基于 this topic ,我没有测试过。

    更新:

    我不知道这是否是你想要做的,但我会在这里发布。以下脚本创建一个带有单选按钮的自定义页面,让用户选择身份验证模式并可选择填写凭据。

    重要提示:

    这些凭证字段没有针对 SQL 注入(inject)的保护!
    [Setup]
    AppName=My Program
    AppVersion=1.5
    DefaultDirName={pf}\My Program

    [Code]
    const
    LT_WindowsAuthentication = 0;
    LT_SQLServerAuthentication = 1;
    var
    LoginType: Integer;
    UsernameEdit: TNewEdit;
    UsernameLabel: TLabel;
    PasswordEdit: TNewEdit;
    PasswordLabel: TLabel;

    procedure OnLoginTypeChange(Sender: TObject);
    var
    EditColor: TColor;
    LabelColor: TColor;
    begin
    LoginType := TNewRadioButton(Sender).Tag;
    UsernameEdit.Enabled := LoginType = LT_SQLServerAuthentication;
    PasswordEdit.Enabled := LoginType = LT_SQLServerAuthentication;
    case LoginType of
    LT_WindowsAuthentication:
    begin
    EditColor := clBtnFace;
    LabelColor := clGray;
    end;
    LT_SQLServerAuthentication:
    begin
    EditColor := clWindow;
    LabelColor := clBlack;
    end;
    end;
    UsernameEdit.Color := EditColor;
    PasswordEdit.Color := EditColor;
    UsernameLabel.Font.Color := LabelColor;
    PasswordLabel.Font.Color := LabelColor;
    end;

    procedure InitializeWizard;
    var
    LoginPage: TWizardPage;
    begin
    LoginPage := CreateCustomPage(wpWelcome, 'DB Login', 'Choose a login type to continue...');
    with TNewRadioButton.Create(WizardForm) do
    begin
    Parent := LoginPage.Surface;
    Left := 0;
    Top := 0;
    Width := LoginPage.Surface.ClientWidth;
    Checked := True;
    Tag := 0;
    Caption := 'Windows authentication';
    OnClick := @OnLoginTypeChange;
    end;
    with TNewRadioButton.Create(WizardForm) do
    begin
    Parent := LoginPage.Surface;
    Left := 0;
    Top := 20;
    Width := LoginPage.Surface.ClientWidth;
    Checked := False;
    Tag := 1;
    Caption := 'SQL Server authentication';
    OnClick := @OnLoginTypeChange;
    end;

    UsernameLabel := TLabel.Create(WizardForm);
    with UsernameLabel do
    begin
    Parent := LoginPage.Surface;
    Left := 12;
    Top := 44;
    Width := 200;
    Font.Color := clGray;
    Font.Style := [fsBold];
    Caption := 'Username';
    end;
    UsernameEdit := TNewEdit.Create(WizardForm);
    with UsernameEdit do
    begin
    Parent := LoginPage.Surface;
    Left := 12;
    Top := UsernameLabel.Top + UsernameLabel.Height + 6;
    Width := 200;
    Color := clBtnFace;
    Enabled := False;
    end;

    PasswordLabel := TLabel.Create(WizardForm);
    with PasswordLabel do
    begin
    Parent := LoginPage.Surface;
    Left := 12;
    Top := UsernameEdit.Top + UsernameEdit.Height + 6;
    Width := 200;
    Font.Color := clGray;
    Font.Style := [fsBold];
    Caption := 'Password';
    end;
    PasswordEdit := TNewEdit.Create(WizardForm);
    with PasswordEdit do
    begin
    Parent := LoginPage.Surface;
    Left := 12;
    Top := PasswordLabel.Top + PasswordLabel.Height + 6;
    Width := 200;
    Color := clBtnFace;
    Enabled := False;
    PasswordChar := '*';
    end;
    end;

    // and in your connection event then use
    case LoginType of
    LT_WindowsAuthentication:
    ADOConnection.ConnectionString :=
    'Provider=SQLOLEDB;' + // provider
    'Data Source=Default\SQLSERVER;' + // server name
    'Initial Catalog=Northwind;' + // default database
    'Integrated Security=SSPI;'; // trusted connection
    LT_SQLServerAuthentication:
    ADOConnection.ConnectionString :=
    'Provider=SQLOLEDB;' + // provider
    'Data Source=Default\SQLSERVER;' + // server name
    'Initial Catalog=Northwind;' + // default database
    'User Id=' + UsernameEdit.Text + ';' + // user name
    'Password=' + PasswordEdit.Text + ';'; // password
    end;

    关于inno-setup - Inno 设置 : connect to sql using windows authentication,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12728450/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com