我们有一个在 SQL 2005 上运行的数据库。其中一个存储过程使用链接服务器从 Active Directory 中查找用户的电子邮件地址。对链接服务器的调用发生在数据库函数中。
我第一次可以从我的 Asp.Net 应用程序成功调用,但之后会定期失败,并出现以下错误:
{"无法执行请求的操作,因为链接服务器\"ADSI\"的 OLE DB 提供程序\"ADsDSOObject\"不支持所需的事务接口(interface)。"}
似乎调用函数之间的时间量会影响链接服务器查询是否正常工作。我没有使用任何交易。当我尝试在快速临时 SQL 脚本中调用该函数时,它每次都运行良好(即使在快速连续测试时也是如此)。
如果我不再尝试再次调用该过程,是否有某种交易处于打开状态而自然死亡?我在这里不知所措。
这是存储过程中的简单调用:
DECLARE @email varchar(50)
SELECT @email = LEFT(mail, 50)
FROM OPENQUERY (
ADSI,
'SELECT mail, sAMAccountName FROM ''LDAP://DC=Katz,DC=COM'' WHERE objectCategory = ''Person'' AND objectClass = ''User'''
)
WHERE sAMAccountName = CAST(@LoginName AS varchar(35))
RETURN @email
最佳答案
我经常使用 SQL Server 链接服务器,虽然很少使用 LDAP 查询……但我很好奇并阅读了 Ric Tokyo 上一篇文章中链接到的 Microsoft 支持页面。底部写着:
It is typical for a directory server to enforce a server limitation on the number of objects that will be returned for a given query. This is to prevent denial-of-service attacks and network overloading. To properly query the directory server, large queries should be broken up into many smaller ones. One way to do this is through a process called paging. While paging is available through ADSI's OLEDB provider, there is currently no way available to perform it from a SQL distributed query. This means that the total number of objects that can be returned for a query is the server limit. In the Windows 2000 Active Directory, the default server limit is 1,000 objects.
我认为它失败的原因(或没有)取决于是从应用程序还是从“快速临时 sql 脚本”(如您所说)调用它,这可能与安全上下文有关操作正在执行。根据链接服务器连接的设置方式,操作可能会在各种可能的凭据下执行,具体取决于您启动查询的方式。
我不知道,但这是我最好的猜测。我会查看链接服务器配置,特别是链接服务器设置,哪些凭据集用作跨链接服务器执行的操作运行的安全上下文。
关于SQL 2005 链接服务器查询定期失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/485908/