使用Windows安全性和模拟的远程连接到SQL Server

发布于 2025-01-24 05:48:23 字数 1706 浏览 3 评论 0原文

我想调整Windows登录到DBMail(用于发送附件),第一步是简单的打开连接到存储DBMail配置的SQL Server。

我已经在名为dbmail的Windows中创建了一个帐户,然后为其创建了一个SQL登录:

 CREATE LOGIN [QQQQQQQ\dbmail] FROM WINDOWS

我将此SQL登录所需的许可设置为(SQLADMINISTRATOR)

许可

然后,我尝试使用此连接字符串连接到SQL:

ATT_tds_STRING = "Data Source=localhost; Database=YYYYY; uid=QQQQQQQQ\dbmail; pwd=xxxxxxxxxxxx; Integrated Security=SSPI;"

我放置在com-object中的功能

Public Function DbMailSendMail(CN As String, DbMailProfileName As String, SmSender As String, SmRecptLst As String, SmCCLst As String, SmBCCLst As String, SmSubject As String, SmMsg As String, SmAttach As String) As String Implements IDbMail.DbMailSendMail
    Dim SQLCN As New SqlClient.SqlConnection(CN)
    SQLCN.Open()
    Try
        Dim CMD As New SqlClient.SqlCommand($"EXEC msdb.dbo.sp_send_dbmail @body_format = 'HTML', " &
        ....

不幸的是,当我从ASP页面调用我的功能时,

   Dim Mailer1, Res1
   Set Mailer1 = Server.CreateObject("TDS.DbMail")
   Res1 = Mailer1.DbMailSendMail (ATT_tds_STRING, "ZZZZZZZ", "", Request.Form("Mailto"), "", "", Request.Form("title"), Request.Form("body"), "C:\www\tdsv5\Images\BeOS_Help.gif")

我会得到一个奇怪的结果

.NET SQLCLCLIENT数据提供商错误'80131904'
用户“ NT权限\ iusr”登录失败。

我希望Windows身份验证在sqlclient.sqlconnection(cn)带有登录QQQQQQQQ \ dbmail(因为我使用恰好使用Windows登录和SSPI安全性),但是Windows似乎正在使用IIS Incerseration nt promentation nt wertional ancement nt wertion connect connect connect到SQL Server。

I want to tune Windows login to dbmail (for sending attachment), first step is simple open connection to SQL Server where the dbmail configuration is stored.

I have created an account in Windows named dbmail, and then I created a SQL login for it:

 CREATE LOGIN [QQQQQQQ\dbmail] FROM WINDOWS

I set needed permission for this SQL login to (SqlAdministrator).

Permission

Then I try to connect to SQL with this connection string:

ATT_tds_STRING = "Data Source=localhost; Database=YYYYY; uid=QQQQQQQQ\dbmail; pwd=xxxxxxxxxxxx; Integrated Security=SSPI;"

My function placed inside COM-object

Public Function DbMailSendMail(CN As String, DbMailProfileName As String, SmSender As String, SmRecptLst As String, SmCCLst As String, SmBCCLst As String, SmSubject As String, SmMsg As String, SmAttach As String) As String Implements IDbMail.DbMailSendMail
    Dim SQLCN As New SqlClient.SqlConnection(CN)
    SQLCN.Open()
    Try
        Dim CMD As New SqlClient.SqlCommand(
quot;EXEC msdb.dbo.sp_send_dbmail @body_format = 'HTML', " &
        ....

When I call my function from ASP page

   Dim Mailer1, Res1
   Set Mailer1 = Server.CreateObject("TDS.DbMail")
   Res1 = Mailer1.DbMailSendMail (ATT_tds_STRING, "ZZZZZZZ", "", Request.Form("Mailto"), "", "", Request.Form("title"), Request.Form("body"), "C:\www\tdsv5\Images\BeOS_Help.gif")

Unfortunately I get a strange result

.Net SqlClient Data Provider error '80131904'
Login failed for user 'NT AUTHORITY\IUSR'.

I expect Windows authentication in SqlClient.SqlConnection(CN) with login QQQQQQQ\dbmail (because I use exactly Windows login and SSPI security), however Windows appears to be using IIS impersonation account NT AUTHORITY\IUSR to connect to SQL Server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往日 2025-01-31 05:48:23

根据@Charlieface的建议,我已经创建了登录名

 CREATE LOGIN [NT AUTHORITY\IUSR] FROM WINDOWS

,并设置为MSDB

之后,一切正常。连接字符串是

 ATT_tds_STRING = "Data Source=localhost; Integrated Security=SSPI"

According advice @Charlieface, I have created login

 CREATE LOGIN [NT AUTHORITY\IUSR] FROM WINDOWS

and set up to this login special roles in MSDB

DatabasemailUserRole

After that all working fine. Connection string is

 ATT_tds_STRING = "Data Source=localhost; Integrated Security=SSPI"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文