开发者

ADOX leaving file handles open

Has anybody ever had trouble with the ADOX library leaving file handles open?

I am experiencing a strange issue with a VB6 -> VB.Net conversion. There is a function that uses ADOX to look through the tables in a given database, and reset the seed values of any columns in said tables with the auto increment property set to true.

I tracked the issue down to a call of "col.Properties("Autoincrement").Value". If this line of code is commented out, then the file handle properly terminates when I close both the ADO and the ADOX connections at the end of the function. If I leave that line in, the handle stays open despite the closing calls and forcing garbage collection.

Here's how I am closing the objects:

System.Runtime.InteropServices.Marshal.ReleaseComObject(adoConn)  
Dim connection As ADODB.Connection = cat.ActiveConnection  
If Not connection Is Nothing Then  
   connection.Close()  
End If  
cat.ActiveConnection = Nothing  
cat = Nothing  

adoConn is the ADO connection, and cat is the ADOX.Catalog object. col (from before) is an ADOX.Column object used with the catal开发者_StackOverflowog object.

I originally tried to convert this algorithm to use ADO.Net, and using the DataSet object I got close but was unable to figure out how to determine whether or not a table column was set to auto increment. This is with Access 2000 databases btw.


I just had the problem of a lockfile being left over after creating a database using ADOX. Making sure the connection is closed and the lockfile isn't being used by any of your programs resources might help:

System.Runtime.InteropServices.Marshal.ReleaseComObject(adoConn)

Dim connection As ADODB.Connection = cat.ActiveConnection

If Not connection Is Nothing Then
  connection.Close()   
End If   

'Try adding this below
System.Runtime.InteropServices.Marshal.ReleaseComObject(connection)
System.Runtime.InteropServices.Marshal.ReleaseComObject(cat)
GC.Collect()

cat.ActiveConnection = Nothing   
cat = Nothing 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜