Inno setup Inno安装程序:使用windows身份验证连接到sql
有人能告诉我如何通过inno使用windows身份验证连接到SQL 2008吗?目前我使用的是inno,用户也需要windows身份验证选项。请建议 当我们讨论您在问题中链接的示例时,从连接字符串(Inno setup Inno安装程序:使用windows身份验证连接到sql,inno-setup,Inno Setup,有人能告诉我如何通过inno使用windows身份验证连接到SQL 2008吗?目前我使用的是inno,用户也需要windows身份验证选项。请建议 当我们讨论您在问题中链接的示例时,从连接字符串(User Id和Password)中删除凭据属性就足够了,包括以下内容之一: integratedsecurity=SSPI Trusted_Connection=True 这个答案只是基于,我还没有测试过 更新: 我不知道你是否想这么做,但我会把它贴在这里。下面的脚本创建了一个带有单选按钮的自定义页
User Id
和Password
)中删除凭据属性就足够了,包括以下内容之一:
integratedsecurity=SSPI代码>
Trusted_Connection=True代码>
[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;
谢谢,但是有没有办法也提供用户凭据?这样就可以连接到远程sql server。您的意思是通过凭据或Windows身份验证提供给用户登录?我的意思是,通过ado连接提供Windows凭据。假设SQL server位于某台远程计算机上,用户需要使用该计算机的windows凭据连接到该计算机,因为当前的windows用户可能与SQL远程服务器计算机中的用户不同。我不太确定您的意思。如果以这种方式配置服务器端,则可以使用本地用户的Windows凭据连接到远程计算机。如果我是SQL server,你只知道我在哪里(服务器位置),你说我信任你(你给我Windows凭据以进行身份验证)。然后,我必须配置为允许在一个全球性的方式,我必须有你作为一个用户,可以通过Windows身份验证登录添加。当然,与我的联系必须安全可靠,否则你就倒霉了。