Memory leaks?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • T Clancey

    #1

    Memory leaks?

    Hi, I have an app which connects to an Access database on a server, there
    are around 10 clients. It's a fairly heavy data intensive app, but most of
    the traffic is look up data.

    While the system appears to run completely error free around every 6 weeks
    the server stops serving the network share where the database resides. When
    a client tried to connect you get an error message something like Not enough
    resources or disk failure. Resetting the server cleares the problem. More
    worrying is a large database corruption that happened just a couple of days
    ago.

    As far as I can tell my code is correct and I'm not leaving anything open or
    connected that shouldn't be. Is there any way to trace or track what
    connections and/or resources are being used by each Client? Or if my code
    is generating any memory leaks?

    Cheers,
    Tull.


  • teslar91@hotmail.com

    #2
    Re: Memory leaks?

    Check to see if your Access db is being opened repeatedly and never
    closed, or if a large number of file locks are accumulating on it. For
    a Windows server, you can check here:

    Control Panel/Administrative Tools/Computer Management/Shared
    Folders/Open Files

    Comment

    • Steve Long

      #3
      Re: Memory leaks?

      This can be a problem with Access Databases and can even cause corruption
      (IMO, base on anecdotal experience). I would back this database up daily so
      that you don't loose too much data, in case corruption does occur.
      Additionally, I would compact this database often if you are doing any kind
      of data manipulation at all. You can do this programmaticall y via the JRO
      library.

      Dim src As String

      Dim dest As String

      Dim tmpDB As String

      Dim je As JRO.JetEngine = New JetEngineClass

      tmpDB = CLog.GetAppPath () & "\tmp.mdb"

      src = con.ConnectionS tring ' ADODB connection that has already been
      opened

      dest = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & tmpDB & ";Jet
      OLEDB:Engine Type=5"

      If con.State <ADODB.ObjectSt ateEnum.adState Closed Then

      con.Close()

      End If

      je.CompactDatab ase(src, dest)

      Kill(m_sDBName) ' m_sDBName is the name of the database and it's location

      File.Move(tmpDB , m_sDBName)

      con.Open()

      je = Nothing

      Hope you were looking for something like this. Otherwise, sorry I posted
      nonsense for you.

      Steve

      "T Clancey" <tull@idcodewar e.co.ukwrote in message
      news:KomdnVErmf 41kbPYRVnyjA@bt .com...
      Hi, I have an app which connects to an Access database on a server, there
      are around 10 clients. It's a fairly heavy data intensive app, but most
      of the traffic is look up data.
      >
      While the system appears to run completely error free around every 6 weeks
      the server stops serving the network share where the database resides.
      When a client tried to connect you get an error message something like Not
      enough resources or disk failure. Resetting the server cleares the
      problem. More worrying is a large database corruption that happened just
      a couple of days ago.
      >
      As far as I can tell my code is correct and I'm not leaving anything open
      or connected that shouldn't be. Is there any way to trace or track what
      connections and/or resources are being used by each Client? Or if my code
      is generating any memory leaks?
      >
      Cheers,
      Tull.
      >

      Comment

      • Scott M.

        #4
        Re: Memory leaks?

        I think you've got a lot of unneccessary code here. All you need is this:

        dim dbPath As String = (path to database here)
        dim conString As String = "Provider=Micro soft.JET.OLEDB. 4.0;Data Source=" &
        dbPath

        dim con As New OleDB.OleDBConn ection(conStrin g)

        Try
        con.Open

        ...your database code here...

        Catch ex As OleDbException
        ...handle database exceptions here...
        Catch ex As Exception
        ...handle CLR exceptions here
        Finally
        con.close
        con.dispose
        End Try

        Notes:

        In ADO.NET, you can call the .Close() method of any object that has one
        without worrying about whether it is actually open or not. If it is open,
        it will close it. If it is already closed, no action is taken & no
        exception is thrown.

        You should always open your connection inside of a Try...Catch and you
        should always close it and dispose of it in the Try...Catch's Finally so it
        will always get closed and disposed, even if there are exceptions thrown
        along the way.


        "Steve Long" <Steve_Noneya@N oSpam.comwrote in message
        news:O4sfzhj7GH A.4996@TK2MSFTN GP03.phx.gbl...
        This can be a problem with Access Databases and can even cause corruption
        (IMO, base on anecdotal experience). I would back this database up daily
        so that you don't loose too much data, in case corruption does occur.
        Additionally, I would compact this database often if you are doing any
        kind of data manipulation at all. You can do this programmaticall y via the
        JRO library.
        >
        Dim src As String
        >
        Dim dest As String
        >
        Dim tmpDB As String
        >
        Dim je As JRO.JetEngine = New JetEngineClass
        >
        tmpDB = CLog.GetAppPath () & "\tmp.mdb"
        >
        src = con.ConnectionS tring ' ADODB connection that has already been
        opened
        >
        dest = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & tmpDB & ";Jet
        OLEDB:Engine Type=5"
        >
        If con.State <ADODB.ObjectSt ateEnum.adState Closed Then
        >
        con.Close()
        >
        End If
        >
        je.CompactDatab ase(src, dest)
        >
        Kill(m_sDBName) ' m_sDBName is the name of the database and it's
        location
        >
        File.Move(tmpDB , m_sDBName)
        >
        con.Open()
        >
        je = Nothing
        >
        Hope you were looking for something like this. Otherwise, sorry I posted
        nonsense for you.
        >
        Steve
        >
        "T Clancey" <tull@idcodewar e.co.ukwrote in message
        news:KomdnVErmf 41kbPYRVnyjA@bt .com...
        >Hi, I have an app which connects to an Access database on a server, there
        >are around 10 clients. It's a fairly heavy data intensive app, but most
        >of the traffic is look up data.
        >>
        >While the system appears to run completely error free around every 6
        >weeks the server stops serving the network share where the database
        >resides. When a client tried to connect you get an error message
        >something like Not enough resources or disk failure. Resetting the
        >server cleares the problem. More worrying is a large database corruption
        >that happened just a couple of days ago.
        >>
        >As far as I can tell my code is correct and I'm not leaving anything open
        >or connected that shouldn't be. Is there any way to trace or track what
        >connections and/or resources are being used by each Client? Or if my
        >code is generating any memory leaks?
        >>
        >Cheers,
        >Tull.
        >>
        >
        >

        Comment

        • Steve Long

          #5
          Re: Memory leaks?

          Hmmm, didn't know that. Thanks Scott. I guess I was just a little scardy
          cat... :)

          S

          "Scott M." <s-mar@nospam.nosp amwrote in message
          news:%23pUZO6l7 GHA.4996@TK2MSF TNGP04.phx.gbl. ..
          >I think you've got a lot of unneccessary code here. All you need is this:
          >
          dim dbPath As String = (path to database here)
          dim conString As String = "Provider=Micro soft.JET.OLEDB. 4.0;Data Source="
          & dbPath
          >
          dim con As New OleDB.OleDBConn ection(conStrin g)
          >
          Try
          con.Open
          >
          ...your database code here...
          >
          Catch ex As OleDbException
          ...handle database exceptions here...
          Catch ex As Exception
          ...handle CLR exceptions here
          Finally
          con.close
          con.dispose
          End Try
          >
          Notes:
          >
          In ADO.NET, you can call the .Close() method of any object that has one
          without worrying about whether it is actually open or not. If it is open,
          it will close it. If it is already closed, no action is taken & no
          exception is thrown.
          >
          You should always open your connection inside of a Try...Catch and you
          should always close it and dispose of it in the Try...Catch's Finally so
          it will always get closed and disposed, even if there are exceptions
          thrown along the way.
          >
          >
          "Steve Long" <Steve_Noneya@N oSpam.comwrote in message
          news:O4sfzhj7GH A.4996@TK2MSFTN GP03.phx.gbl...
          >This can be a problem with Access Databases and can even cause corruption
          >(IMO, base on anecdotal experience). I would back this database up daily
          >so that you don't loose too much data, in case corruption does occur.
          >Additionally , I would compact this database often if you are doing any
          >kind of data manipulation at all. You can do this programmaticall y via
          >the JRO library.
          >>
          >Dim src As String
          >>
          >Dim dest As String
          >>
          >Dim tmpDB As String
          >>
          >Dim je As JRO.JetEngine = New JetEngineClass
          >>
          >tmpDB = CLog.GetAppPath () & "\tmp.mdb"
          >>
          >src = con.ConnectionS tring ' ADODB connection that has already
          >been opened
          >>
          >dest = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & tmpDB & ";Jet
          >OLEDB:Engine Type=5"
          >>
          >If con.State <ADODB.ObjectSt ateEnum.adState Closed Then
          >>
          >con.Close()
          >>
          >End If
          >>
          >je.CompactData base(src, dest)
          >>
          >Kill(m_sDBName ) ' m_sDBName is the name of the database and it's
          >location
          >>
          >File.Move(tmpD B, m_sDBName)
          >>
          >con.Open()
          >>
          >je = Nothing
          >>
          >Hope you were looking for something like this. Otherwise, sorry I posted
          >nonsense for you.
          >>
          >Steve
          >>
          >"T Clancey" <tull@idcodewar e.co.ukwrote in message
          >news:KomdnVErm f41kbPYRVnyjA@b t.com...
          >>Hi, I have an app which connects to an Access database on a server,
          >>there are around 10 clients. It's a fairly heavy data intensive app,
          >>but most of the traffic is look up data.
          >>>
          >>While the system appears to run completely error free around every 6
          >>weeks the server stops serving the network share where the database
          >>resides. When a client tried to connect you get an error message
          >>something like Not enough resources or disk failure. Resetting the
          >>server cleares the problem. More worrying is a large database
          >>corruption that happened just a couple of days ago.
          >>>
          >>As far as I can tell my code is correct and I'm not leaving anything
          >>open or connected that shouldn't be. Is there any way to trace or track
          >>what connections and/or resources are being used by each Client? Or if
          >>my code is generating any memory leaks?
          >>>
          >>Cheers,
          >>Tull.
          >>>
          >>
          >>
          >
          >

          Comment

          Working...