我正在接受ADO自动生成的一些不需要的元数据请求。使用SQLOLEDB替换默认MSDASQL提供程序后,行为开始。我也尝试了SQLOLEDB,行为似乎是一样的。
从IDE中重现问题已经证明是困难的,因为它似乎有点随机发生。更令人担忧的是,这些查询似乎要求先前打开(然后关闭)记录集的元数据。
答案 0 :(得分:1)
我在XP机器上使用VB6 SP6中的ADO 2.8进行了一些与不需要的NO_BROWSETABLE / fmtonly / 1 = 2查询相关的奇怪行为。
以下代码将重现该行为。
Private Sub Form_Load()
Dim oConn As ADODB.Connection
Set oConn = New ADODB.Connection
'oConn.Open "DRIVER=SQL Server;SERVER=***;UID=***;password=***;APP=***"
'oConn.Open "Provider=SQLOLEDB;SERVER=***;UID=***;password=***;APP=***"
'oConn.Open "Provider=SQLNCLI10;Server=***;UID=***;PWD=***;APP=***"
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
' Execute the first query
rst.Open "select 1", oConn
rst.Close
' Execute the second query without specifying a connection
rst.Open "select 2"
End Sub
我使用三个不同的提供程序测试了上面的代码。以下是SQL Server Profiler结果。
提供商1(MSDASQL)
select 1
go
select 2
go
提供商2(SQLOLEDB)
select 1
go
-- This comes after executing the second query. Notice the query between FMTONLY ON/OFF is the FIRST query.
SET NO_BROWSETABLE ON
go
SET FMTONLY ON select 1 SET FMTONLY OFF
go
SET NO_BROWSETABLE OFF
go
select 2
go
提供商3(SQLNCLI10)
select 1
go
-- This comes after executing the second query. The behavior is the same as for SQLOLEDB, except that 'where 1=2' is appended to the query.
SET NO_BROWSETABLE ON
go
set fmtonly on select 1 where 1=2 set fmtonly off
go
SET NO_BROWSETABLE OFF
go
select 2
go
结论:
如果未在第二个rst.Open中指定连接,则ADO将在继续之前向服务器请求有关PREVIOUS查询的元数据。
rst.Open "select 2", oConn
如上所述指定oConn将消除元数据请求,SQL Server Profiler将为所有三个提供程序生成相同的事件。