[2008] LINQ leaving database attached after disposed
Ok I have a new project I am working on that is using .mdf files and LINQ to SQL. Now the issue is this. I am using multiple mdf files and it seems that if i make an update to the database and save it then close and dispose of the database object and open a new connection, LINQ appears to be leaving that file attached as I can't reopen it afterwords without restarting my application.
I have a class that has a property that returns the datacontext object and i have implemented IDisposable and here is my dispose method. Me.Database is the DataContext object.
Code:
' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
'Check to see if the database object exists
If Not Me.DataBase Is Nothing Then
'If connection is open then close it
If Me.DataBase.Connection.State = ConnectionState.Open Then
'Close the connection
Me.DataBase.Connection.Close()
End If
'Dispose of the connection
Me.DataBase.Connection.Dispose()
'Dispose of the database object
Me.DataBase.Dispose()
End If
End If
End If
Me.disposedValue = True
End Sub
This method appears to be disposing of the database object properly but it is not allow me to reconnect to the database until i close and reopen my application.
Any help is appreciated.
Re: [2008] LINQ leaving database attached after disposed
Show your datacontext class. I don't think you should be needing to perform a dispose explicitly because the datacontext method should be doing that for you.
Re: [2008] LINQ leaving database attached after disposed
The class is much too large to post, so I have attached it. I did not write the class, it is generated by sqlmetal from a database object.
Edit: bah... it is too big tot upload i will put it on my server
http://rscssoftware.com/Files/DECATProDatacontext.txt
Re: [2008] LINQ leaving database attached after disposed
Re: [2008] LINQ leaving database attached after disposed
sorry i was uploading it is there now
Re: [2008] LINQ leaving database attached after disposed
Sorry I asked, that class is huge! :sick:
Can you tell me which method you're calling in this class?
For your purposes, well in general, your class that encapsulates the datacontext as a property shouldn't need to do more than call the .dispose method of the DataContext property. However at this point it's still not clear what's still causing the MDF to be locked.
Re: [2008] LINQ leaving database attached after disposed
ya, that is all I am doing is calling the Dispose method of the database object which is the datacontext, but for some reason it is leaving the database attached... really wierd, I am hoping to not have to manually detach the database myself but if I have to that is where I am headed.