我正在尝试使用 ADO 对 SQL Server 2005 运行(两个)查询:
SELECT
sp.nt_username AS NTUsername,
sp.hostname AS HostName
FROM sys.dm_tran_locks tl
INNER JOIN master.dbo.sysprocesses sp
ON tl.request_session_id = sp.spid
WHERE tl.resource_type = N'APPLICATION'
AND tl.resource_database_id = (
SELECT dbid
FROM master.dbo.sysprocesses
WHERE spid = @@spid)
和 SQL Server 2000 兼容版本:
SELECT
sp.nt_username AS NTUsername,
sp.hostname AS HostName
FROM master.dbo.syslockinfo sli
INNER JOIN master.dbo.sysprocesses sp
ON sli.req_spid = sp.spid
WHERE rsc_type = 10 --10=Appliction
AND rsc_dbid = (
SELECT dbid
FROM master.dbo.sysprocesses
WHERE spid = @@spid)
查询执行良好:
IRecordset rs =new Recordset();
rs.CursorLocation = adUseClient; //the default for a Recordset is adUseServer (Connection.Execute's default is adUseClient)
rs.CursorType := adOpenForwardOnly; //the default
rs.Open(szQuery, conn.ConnectionObject,
adOpenForwardOnly, //CursorType
adLockReadOnly, //LockType
adCmdText);
但随后检查BOF
or的状态EOF
:
if (rs.EOF) then
触发异常:
- HRESULT:0x80004005(未指定的错误)
- 错误消息:“数据提供者或其他服务返回了 E_FAIL 状态”
这个导致 ADO 惨遭失败的查询是怎么回事?
注意:确实有一个匹配的行:
provider
我在连接字符串中使用的是Provider=SQLOLEDB
.
奖金喋喋不休:
系统进程
nt_username nchar(128) hostname nchar(128)
并查询两者 - 但一次一个 - 有效,例如:
SELECT
sp.nt_username AS NTUsername
和
SELECT
sp.hostname AS HostName
工作。查询两者都失败。