Tuesday, November 6, 2012

oledbconnection pooling

Or when is a file close not actually a file close?

Had a snippet of code that first opened a file for shared access, then opened it as exclusive once it started a processing run

If the open routine found the file already open, it closed it, disposed the connection object, and set it to null
You would have thought that would have freed the file from use
No luck. The resulting error was less than clear: Couldn't use ; file already in use.

It was still open hiding in the connection pool

Here's the final solution


         If Not DatabaseConnection Is Nothing Then
            If DatabaseConnection .State = ConnectionState.Open Then
                Try
                    DatabaseConnection .Close()
                    DatabaseConnection .Dispose()
                    DatabaseConnection = Nothing
                    System.Threading.Thread.Sleep(TIME_TO_WAIT_STALL)
                    OleDbConnection.ReleaseObjectPool()  <-- Important line!!!!
                Catch ex As Exception

                End Try
            End If
        End If

Friday, April 20, 2012

COM DLLs in Microsoft Access 2010

When developing a COM add in for Access 2010 (and other MS Office products I suspect), when using regasm to register the DLL, throw both the TLB and the CODEBASE flags

Otherwise Access gets lost, and you get automation errors on referencing the COM objects the DLL supports