Results 1 to 7 of 7

Thread: [2008] LINQ leaving database attached after disposed

  1. #1

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    [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.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  3. #3

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    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
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] LINQ leaving database attached after disposed

    404.

  5. #5

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2008] LINQ leaving database attached after disposed

    sorry i was uploading it is there now
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] LINQ leaving database attached after disposed

    Sorry I asked, that class is huge!

    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.

  7. #7

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    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.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width