我无法弄清楚为什么会这样......
我有以下代码:
var connection = new Connection();
connection.CursorLocation = CursorLocationEnum.adUseClient;
connection.ConnectionString = GetOdbcConnectionString(connectionString);
connection.Open();
var rs = new Recordset();
rs.CursorType = CursorTypeEnum.adOpenStatic;
rs.CursorLocation = CursorLocationEnum.adUseClient;
rs.LockType = LockTypeEnum.adLockBatchOptimistic;
// this issues the SQL SELECT * FROM Test
rs.Open("SELECT * FROM Test", connection);
rs.ActiveConnection = null;
rs.Close();
rs = null;
var rs2 = new Recordset();
rs2.CursorType = CursorTypeEnum.adOpenStatic;
rs2.CursorLocation = CursorLocationEnum.adUseClient;
rs2.LockType = LockTypeEnum.adLockBatchOptimistic;
/* this doesn't output the expected SQL...it outputs:
declare @p1 int
set @p1=180150003
declare @p3 int
set @p3=4
declare @p4 int
set @p4=1
declare @p5 int
set @p5=-1
exec sp_cursoropen @p1 output,N'SELECT * FROM Test',@p3 output,@p4 output,@p5 output
select @p1, @p3, @p4, @p5
*/
rs2.Open("SELECT * FROM Test", connection);
如果我在打开rs2之前手动Marshal.ReleaseComObject(rs)
,第二个记录集会发出与第一个相同的简单SQL,而不使用游标。必须从第一个rs上挂起它......但是当连接和记录集都设置了OpenStatic和UseClient时,我不知道是什么,为什么或为什么它会导致使用游标。
答案 0 :(得分:0)
长时间撞击我的头后,终于找到了问题:
DRIVER={SQL Server};
需要更改为
Provider=SQLOLEDB;