谁能告诉我如何使用 Windows 身份验证通过 inno 连接到 SQL 2008?目前我正在使用ado 连接从 inno连接到 SQL ,用户也需要 windows 身份验证选项。请建议。
问问题
2038 次
1 回答
3
当我们谈论您在问题中链接的示例并包含以下内容之一时,从您的连接字符串(User Id
和)中删除凭据属性就足够了:Password
Integrated Security=SSPI;
Trusted_Connection=True;
这个答案只是基于this topic
,我没有测试过。
更新:
我不知道这是否是你想要做的,但我会在这里发布。以下脚本创建一个带有单选按钮的自定义页面,让用户选择身份验证模式并可选择填写凭据。
重要的:
这些凭证字段没有针对 SQL 注入的保护!
[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;
于 2012-10-04T14:06:13.167 回答