是否有一个属性我必须在某处设置以指示记录集应该断开连接?我无法设置Recordset.ActiveConnection = False,因为我得到一个异常(“无法更改具有Command对象作为其来源的Recordset对象的ActiveConnection属性.”).我设置Command.ActiveConnection = False,但是一旦我关闭连接对象,就不会停止记录集关闭.
片段:
Dim conn as New ADODB.Connection()conn.Open("connectionString","UserID","Password")Dim cmd as New ADODB.Command()' Set some parameters on the command.cmd.ActiveConnection = conncmd.CommandText = "StoredProcedurename"cmd.CommandType = ADODB.CommandTypeEnum.adCmdstoredProcDim rs as New ADODB.Recordset()rs.Open(cmd)Dim clonedRS as ADODB.Recordset = rs.Clone() ' one attempt to disconnect recordsetrs.Close() ' Does not close cloned recordsetcmd.ActiveConnection = nothing ' another try at disconnecting recordsetconn.Close() ' Always closes the recordset,even the cloned onereturn clonedRS ' Sadly,this is closed Now.解决方法 我不知道这是否可以解决您的问题,但我进行了Google搜索并找到了这篇文章 Disconnect an ADO Recordset generated from a Command object,您可以使用它来修改您的代码,如下所示:
Dim conn as New ADODB.Connection()conn.Open("connectionString","Password")Dim cmd as New ADODB.Command()' Set some parameters on the command.cmd.ActiveConnection = conncmd.CommandText = "StoredProcedurename"cmd.CommandType = ADODB.CommandTypeEnum.adCmdstoredProcDim rs As ADODB.RecordsetWith rs .CursorLocation = adUseClIEnt .Open cmd,CursorType:=adOpenStatic,Options:=adCmdstoredProc Set .ActiveConnection = nothingEnd WithDim clonedRS As ADODB.Recordset = rsSet cmd = nothingconn.Close()rs.Close()Set conn = nothingSet rs = nothingReturn clonedRS
4GuysFromrolla Using Disconnected Recordsets的另一个例子具有相同的方法.
编辑
充实了这个例子.
总结以上是内存溢出为你收集整理的如何在VB.NET Windows应用程序中创建ADODB断开连接的记录集?全部内容,希望文章能够帮你解决如何在VB.NET Windows应用程序中创建ADODB断开连接的记录集?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)