Crystal 报告中的假冒行为

Impersonation In Crystal Reports

我一直在尝试更新与 Crystal 报告交互的 WCF 项目,以使其通过 Windows 身份验证连接到 MS SQL 服务器。 它是一个 WCF 项目,但 运行 作为 Windows 服务而不是通过 IIS。

我正在使用 SimpleImpersonation 进行模拟步骤。 本质上,如果在传入的 SOAP 请求中提供了正确的值,包括 IntegratedSecurity=true,它会模拟另一个用户并尝试使用 IntegratedSecurity 登录。

我的代码看起来像这样:

using (Impersonation.LogonUser(domain, username, password, LogonType.NewCredentials)) {
    reportDocument.Execute();
}

我知道模拟有效,因为我在 using 语句之前和之后打印了 System.Security.Principal.WindowsIdentity.GetCurrent().Name,并且看到用户名在 using 之后更改为我想要的。

我尝试了每一种不同的 LogonType,但我得到了相同的结果。

我在调用 Execute() 时收到一条 Database logon failed 错误消息。 但是,如果我启动 Web 服务 运行 作为我试图模拟的帐户,我能够正确连接到数据库。

我的问题是:

原来我的问题不是模拟,而是数据库驱动程序。我在 https://archive.sap.com/discussions/thread/3621859:

上找到了一条评论

Please check the file "sqlncli.dll" exist in server or not? .. not sure this file or some other dll.

我在服务器上安装了 https://www.microsoft.com/en-us/download/confirmation.aspx?id=50402,我的代码开始自动运行。

我希望 Crystal 报告返回的错误消息更具描述性,但是哦,好吧,至少它是有效的。