Question

How to detect memory leaks?

Asked by: virus_pat

Hi,
I've written an application in VB, which does logging to a database every 15 minutes.  I used an API that helps me to connect to the server and extract data from it.  The problem is that the program gives ADO "Unspecified Error" after it runs for a few days and keeps getting the same error when the program tries to connect to the database.  I check the EventViewer and it saids something about unable to allocate memory for the application.  I think this is a memory leak, I've been looking at the code for a few days and can't find anything wrong.  So, I suspect that the API is having memory leaks.  Is there any tools out there that helps me track memory leaks in VB and even leaks in API?  Thanks in advance.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-08-25 at 20:12:09ID20719817
Topic

Visual Basic Programming

Participating Experts
4
Points
400
Comments
16

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Memory Leak!
    Hi! In my project at work I have memory leaks that I detect with tool called Numega. This tool tell me that I have memory leaks that I don't understand from where they come. here are some of the messages: -84 bytes allocated by operator_new in iostrini.cpp(21), HANDLE: 0x25...
  2. Memory leak in API?
    We've got an application that is displaying some very odd behavior, and we've pinned it down to a few API's. Anyone have any information on any of this? ::GetClassName() ::GetModuleFileName() ::GetWindowText() ::GetModuleFileNameEx() Calling any of the above causes about a...
  3. ADO Memory Leak
    VC++ 6.0 SP5, MDAC 2.8, W2K Pro SP3 I am developing an NT service that uploads data to a database. It will run 24/7. Because of this, memory leaks are of particular concern to me. I wrote a simple application that executes a select from a database continuously until you press...
  4. Memory leak
    Hello, I have an VC6.0 dll that appears to have a memory leak. This leak is reported to my by Memory Validator. Underneath a sniplet of code: CComPtr<ADODB::_Recordset> rs(cmd->Execute(NULL, NULL, ADODB::adCmdStoredProc)); while (!rs->EndOfFile) { std::wstrin...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: virus_patPosted on 2003-08-25 at 21:00:04ID: 9221217

Here is the code if anyone wants to see:

Function GenerateRcvdFaxLog() As String

54    On Error GoTo GenerateRcvdFaxLogErrHandler
      Dim lError As Long
      Dim hServer As Long  'RFax server handle
      Dim lUserList As Long   'user list
      Dim lUserObj As Long 'user object
      Dim lUserInfoObj As Long
      Dim lFaxList As Long 'fax list
      Dim lFaxObj As Long 'fax object
      Dim lFaxInfoObj As Long 'fax info object
      Dim hFax As Long 'fax handle
      Dim lHistoryList As Long 'fax history list
      Dim lHistoryObj As Long 'fax history object

55    hServer = 0
56    lUserList = 0
57    lUserObj = 0
58    lUserInfoObj = 0
59    lFaxList = 0
60    lFaxObj = 0
61    lFaxInfoObj = 0
62    hFax = 0
63    lHistoryList = 0
64    lHistoryObj = 0

      Dim userid As String 'user ID
      Dim suserfaxnum As String
      Dim istatus As Integer
      Dim suniqueid As String
      Dim isANIValid As Integer
      Dim ANI As String
      Dim inumpages As Integer
      Dim lRcvdTime As Long
      Dim sRcvdDateTime As String
      Dim iYear As Integer, iMonth As Integer, iDay As Integer, iHour As Integer, iMin As Integer, iSec As Integer
      Dim itermstatus As Integer
      Dim iErrCode As Integer
      Dim ltranstime As Long
      Dim sEmailStatus As String

65    suserfaxnum = ""
66    userid = ""
67    istatus = 0
68    ANI = ""
69    suniqueid = ""
70    inumpages = 0
71    lRcvdTime = 0
72    sRcvdDateTime = ""
73    iYear = 0
74    iMonth = 0
75    iDay = 0
76    iHour = 0
77    iMin = 0
78    iSec = 0
79    iErrCode = 0
80    ltranstime = 0
81    isANIValid = 0
82    sEmailStatus = ""

      Dim m_TransactionConn As ADODB.Connection
83    Set m_TransactionConn = New ADODB.Connection
      Dim strConn As String
84    strConn = "Provider=sqloledb;Data Source=" & DBServer & ";Initial Catalog=" & DBDatabase & ";User ID=" & DBUserID & ";Password=" & DBPassword & ";"

85    m_TransactionConn.Open strConn
86    If (Not (m_TransactionConn Is Nothing)) Then
87       If (m_TransactionConn.State = adStateClosed) Then
88          ErrorLog "error connecting to database: " & DBServer & ", in module GenerateRcvdFaxLog"
89          GenerateRcvdFaxLog = "error connecting to database: " & DBServer & ", in module GenerateRcvdFaxLog"
            Exit Function
         End If
      Else
90       ErrorLog "error connecting to database: " & DBServer & ", in module GenerateRcvdFaxLog"
91       GenerateRcvdFaxLog = "error connecting to database: " & DBServer & ", in module GenerateRcvdFaxLog"
         Exit Function
      End If

      Dim strSQL As String
92    strSQL = "tblIntFaxInLog"

      Dim rsData As ADODB.Recordset
93    Set rsData = New ADODB.Recordset
94    rsData.CursorType = adOpenKeyset
95    rsData.LockType = adLockOptimistic
96    rsData.Open strSQL, m_TransactionConn
97    If (Not (rsData Is Nothing)) Then
98       If (rsData.State = adStateClosed) Then
99          ErrorLog "error opening table: tblIntFaxInLog, in module GenerateRcvdFaxLog"
100         GenerateRcvdFaxLog = "error opening table: tblIntFaxInLog, in module GenerateRcvdFaxLog"
            Exit Function
         End If
      Else
101      ErrorLog "error opening table: tblIntFaxInLog, in module GenerateRcvdFaxLog"
102      GenerateRcvdFaxLog = "error opening table: tblIntFaxInLog, in module GenerateRcvdFaxLog"
         Exit Function
      End If
      '*********************************************************************************************************
      'remember to remove this line later
      'm_TransactionConn.Execute "delete from tblintfaxinlog"
      '*********************************************************************************************************
103   DebugLog ("start to generate log for incoming faxes")
104   hServer = RFaxCreateServerHandle(RFServer, COMMPROTOCOL_TCPIP, lError)
105   If ((lError = RFAX_SUCCESS) And (hServer <> 0)) Then  'obtained the server handle successfully
106      DebugLog ("connected to fax server: " & RFServer)
         'Create all the objects needed, exit the function if fail to create them
107      lError = RFVB_New(RFO_USERLISTELEMENT_0, lUserObj)
108      If (lError <> RF2VB_SUCCESS) Then
109         ErrorLog "error occured when creating user object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
110         RFaxCloseServerHandle (hServer)
111         GenerateRcvdFaxLog = "error occured when creating user object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
            Exit Function
         End If

112      lError = RFVB_New(RFO_USERINFO_10, lUserInfoObj)
113      If (lError <> RF2VB_SUCCESS) Then
114         ErrorLog "error occured when creating user info object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
115         RFaxCloseServerHandle (hServer)
116         RFVB_Delete (lUserObj)
117         GenerateRcvdFaxLog = "error occured when creating user info object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
            Exit Function
         End If

118      lError = RFVB_New(RFO_FAXLISTELEMENT_0, lFaxObj)
119      If (lError <> RF2VB_SUCCESS) Then
120         ErrorLog "error occured when creating fax object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
121         RFaxCloseServerHandle (hServer)
122         RFVB_Delete (lUserObj)
123         RFVB_Delete (lUserInfoObj)
124         GenerateRcvdFaxLog = "error occured when creating fax object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
            Exit Function
         End If
125      lError = RFVB_New(RFO_FAXINFO_10, lFaxInfoObj)
126      If (lError <> RF2VB_SUCCESS) Then
127         ErrorLog "error occured when creating fax info object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
128         RFaxCloseServerHandle (hServer)
129         RFVB_Delete (lUserObj)
130         RFVB_Delete (lUserInfoObj)
131         RFVB_Delete (lFaxObj)
132         GenerateRcvdFaxLog = "error occured when creating fax info object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
            Exit Function
         End If
133      lError = RFVB_New(RFO_HISTLISTELEMENT_0, lHistoryObj)
134      If (lError <> RF2VB_SUCCESS) Then
135         ErrorLog "error occured when creating history object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
136         RFaxCloseServerHandle (hServer)
137         RFVB_Delete (lUserObj)
138         RFVB_Delete (lUserInfoObj)
139         RFVB_Delete (lFaxObj)
140         RFVB_Delete (lFaxInfoObj)
141         GenerateRcvdFaxLog = "error occured when creating history object, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
            Exit Function
         End If

142      lError = RFaxGetUserList(hServer, 1, lUserList) 'get the list of users
143      If (lError <> RFAX_SUCCESS) Then
144         ErrorLog "error while getting user list, in module GenerateRcvdFaxLog(), error: " & RFError2String(lError)
145         RFaxCloseServerHandle (hServer)
146         RFVB_Delete (lUserObj)
147         RFVB_Delete (lUserInfoObj)
148         RFVB_Delete (lFaxObj)
149         RFVB_Delete (lFaxInfoObj)
150         RFVB_Delete (lHistoryObj)
151         GenerateRcvdFaxLog = "error while getting user list, in module GenerateRcvdFaxLog(), error: " & RFError2String(lError)
            Exit Function
         End If
152      lError = RFaxListGetFirstElement(lUserList, lUserObj)
153      While (lError = RFAX_SUCCESS)
154         userid = ""
155         suserfaxnum = ""
156         userid = Trim(RFVB_GetBString(lUserObj, RFO_ULE1_USERID)) 'UserID
157         lError = RFVB_Clear(RFO_USERINFO_10, lUserInfoObj)
158         lError = RFaxLoadUser2(hServer, 1, 0, userid, "", "", 0, 0, lUserInfoObj)
159         If (lError <> RFAX_SUCCESS) Then
160            ErrorLog "error loading user info for user: " & userid & ", in module GenerateRcvdFaxLog(), error: " & RFError2String(lError)
            Else
161            suserfaxnum = RFVB_GetBString(lUserInfoObj, RFO_UI10_ST_DIDNUM)
            End If   'check if the user info is loaded successfully

162         lError = RFaxGetFaxList(hServer, userid, 0, 0, 1, lFaxList)   'get the list of faxes for the user, 2 means get only sent faxes
163         If (lError <> RFAX_SUCCESS) Then 'there are faxes for the user
164            If (lError <> RFAXERR_NOTFOUND) Then
165               DebugLog ("failed to obtain fax list from user: " & userid & ", error: " & RFError2String(lError))
               End If
            Else
166            DebugLog ("obtained user fax list successfully, for user: " & userid)
167            lError = RFVB_Clear(RFO_FAXLISTELEMENT_0, lFaxObj)
168            lError = RFaxListGetFirstElement(lFaxList, lFaxObj)  'get the first fax in the list
169            If lError <> RFAX_SUCCESS Then
170               DebugLog "there is no fax for user: " & userid
               Else
171               While (lError = RFAX_SUCCESS)   'loop thru the faxes in the fax list
172                  istatus = 0

173                  lError = RFVB_GetInteger(lFaxObj, RFO_FLE0_FAX_STATUS, istatus)   'get status of the fax
174                  If (lError <> RF2VB_SUCCESS) Then
175                     DebugLog "error getting fax status, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
                     Else
176                     ANI = ""
177                     suniqueid = ""
178                     inumpages = 0
179                     lRcvdTime = 0
180                     sRcvdDateTime = ""
181                     iYear = 0
182                     iMonth = 0
183                     iDay = 0
184                     iHour = 0
185                     iMin = 0
186                     iSec = 0
187                     iErrCode = 0
188                     ltranstime = 0
189                     isANIValid = 0
190                     sEmailStatus = ""
191                     If ((istatus = FAXSTAT_DONE_OK) Or (istatus = FAXSTAT_DONE_ERROR)) Then
192                        hFax = 0
193                        lError = RFVB_GetLong(lFaxObj, RFO_FI10_HANDLE, hFax) 'get the fax handle
194                        If (lError <> RF2VB_SUCCESS) Then
195                           DebugLog "error getting fax handle, in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
                           Else
196                           lError = RFVB_Clear(RFO_FAXINFO_10, lFaxInfoObj)
197                           lError = RFaxLoadFax(hServer, hFax, 0, 0, lFaxInfoObj) 'load the fax info into the lNewObj
198                           If ((lError <> RFAX_SUCCESS) And (lError <> RFAXERR_NOTFOUND)) Then
199                              DebugLog "error getting fax info, in module GenerateRcvdFaxLog(), error: " & RFError2String(lError)
                              Else
200                              sEmailStatus = RFVB_GetBString(lFaxInfoObj, RFO_FI10_FROM_NAME)
201                              sEmailStatus = Trim(sEmailStatus)
202                              If ((istatus = FAXSTAT_DONE_ERROR) Or ((sEmailStatus <> "") And (Len(sEmailStatus) > 0) And ((UCase(sEmailStatus)) <> "EMAILPENDING"))) Then
203                                 suniqueid = RFVB_GetBString(lFaxInfoObj, RFO_FI10_UNIQUE_ID)
204                                 lError = RFVB_GetInteger(lFaxInfoObj, RFO_FI10_NUMPAGES, inumpages)
205                                 If (lError <> RF2VB_SUCCESS) Then
206                                    DebugLog "error getting number of pages for fax: " & suniqueid & ", in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
                                    End If
207                                 lError = RFVB_GetInteger(lFaxInfoObj, RFO_FI10_FAX_TERMSTAT, itermstatus)
208                                 If (lError <> RF2VB_SUCCESS) Then
209                                    DebugLog "error getting termination status for fax: " & suniqueid & ", in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
210                                    itermstatus = 0
                                    End If
211                                 lError = RFVB_GetInteger(lFaxInfoObj, RFO_FI10_FAX_ERROR_CODE, iErrCode)
212                                 If (lError <> RF2VB_SUCCESS) Then
213                                    DebugLog "error getting termination status for fax: " & suniqueid & ", in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
214                                    iErrCode = 0
                                    End If
215                                 lError = RFVB_GetLong(lFaxInfoObj, RFO_FI10_SEND_TIME, ltranstime)
216                                 If (lError <> RF2VB_SUCCESS) Then
217                                    DebugLog "error getting transmission time for fax: " & suniqueid & ", in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
218                                    ltranstime = 0
                                    End If

219                                 lError = RFaxGetHistoryList(hServer, hFax, lHistoryList)
220                                 If (lError <> RFAX_SUCCESS) Then
221                                    DebugLog "error getting history list for fax: " & suniqueid & ", in module GenerateRcvdFaxLog(), error: " & RFError2String(lError)
                                    Else
222                                    lError = RFVB_Clear(RFO_HISTLISTELEMENT_0, lHistoryObj)
223                                    lError = RFaxListGetFirstElement(lHistoryList, lHistoryObj)  'get the first fax in the list
224                                    While (lError = RFAX_SUCCESS) 'loop thru the history list elements
                                          Dim histType As Byte
225                                       lError = RFVB_GetByte(lHistoryObj, RFO_HLE0_TYPE, histType)
226                                       If (lError <> RF2VB_SUCCESS) Then
227                                          DebugLog "error getting history type for fax: " & suniqueid & ", in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
                                          Else
228                                          If ((histType = HISTTYPE_TXRXINFO) Or (histType = HISTTYPE_SECUREDOCS)) Then 'only get the info if it is transmission history type
229                                             RFVB_GetInteger lHistoryObj, RFO_HLE0_TRX_FLAGS, isANIValid
230                                             If ((isANIValid > 3 And isANIValid < 8) Or (isANIValid > 11 And isANIValid < 16)) Then
231                                                ANI = RFVB_GetBString(lHistoryObj, RFO_HLE0_TRX_ANI)
                                                Else
232                                                ANI = ""
                                                End If 'check if the ANI is valid
233                                             lError = RFVB_GetLong(lHistoryObj, RFO_HLE0_DATETIME, lRcvdTime)
234                                             If (lError <> RF2VB_SUCCESS) Then
235                                                DebugLog "error getting transmission history time for fax: " & suniqueid & ", in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
236                                                sRcvdDateTime = ""
                                                Else
237                                                If (lRcvdTime > 0) Then
238                                                   RFaxCTimeToValues lRcvdTime, iYear, iMonth, iDay, iHour, iMin, iSec
239                                                   sRcvdDateTime = iYear & "/" & iMonth & "/" & iDay & " " & iHour & ":" & iMin & ":" & iSec
                                                   Else
240                                                   sRcvdDateTime = ""
                                                   End If 'double check if tranmission time is valid
                                                End If 'check if transmission time is ok
                                             End If   'only get the info if it is transmission or secure doc history type
                                          End If 'check if getting the history type is ok
241                                       lError = RFVB_Clear(RFO_HISTLISTELEMENT_0, lHistoryObj)
242                                       lError = RFaxListGetNextElement(lHistoryList, lHistoryObj)
243                                    Wend 'loop thru the history list elements
                                    End If 'test whether the history list is obtained successfully
244                                 RFaxCloseListHandle (lHistoryList)  'close the history list
245                                 lHistoryList = 0

246                                 If (sRcvdDateTime = "") Then
247                                    sRcvdDateTime = "1900/1/1 0:0:0"
                                    End If
248                                 rsData.AddNew
249                                 rsData!userid = userid
250                                 rsData!FaxNo = suserfaxnum
251                                 rsData!RightFaxJobID = suniqueid
252                                 If (ANI <> "") Then
253                                    rsData!Caller = ANI
                                    End If
254                                 rsData!CallTime = sRcvdDateTime
255                                 rsData!NoOfPage = inumpages
256                                 rsData!Duration = ltranstime
257                                 If (istatus = FAXSTAT_DONE_OK) And ((UCase(sEmailStatus)) = "EMAILSUCCESSFUL") Then
258                                    rsData!callstatus = "S"
259                                 ElseIf (istatus <> FAXSTAT_DONE_OK) Then
                                       Dim errString As String
260                                    rsData!callstatus = "F"
261                                    If ((itermstatus > 0) And (itermstatus < 24)) Then
262                                       errString = TermCode2String(itermstatus)
263                                       rsData!Error = errString
                                       Else
264                                       errString = ErrCode2String(iErrCode)
265                                       rsData!Error = errString
                                       End If
                                    Else
                                       Dim errString2 As String
266                                    rsData!callstatus = "F"
267                                    If ((itermstatus > 0) And (itermstatus < 24)) Then
268                                       errString2 = TermCode2String(itermstatus)
269                                       rsData!Error = errString2
                                       Else
270                                       errString2 = ErrCode2String(iErrCode)
271                                       rsData!Error = errString2
                                       End If
272                                    If ((sEmailStatus <> "EMAILSUCCESSFUL") And (sEmailStatus <> "")) Then
273                                       rsData!Error = sEmailStatus
                                       End If
                                    End If
274                                 rsData!icarestatus = "P"
275                                 rsData!creationdate = Now
276                                 rsData.Update

                                    '                                 lError = RFVB_SetBString(lFaxInfoObj, RFO_FI10_TO_CITYSTATE, "FAXLOGGED")
                                    '---------------------------********************************--------------------------------
                                    'UNCOMMENT THESE LINES WHEN FINISHED
277                                 If (IsDeleteAsLogged = True) Then
278                                    lError = RFaxDeleteFax(hServer, hFax)
279                                    If (lError <> RF2VB_SUCCESS) Then
280                                       ErrorLog "error deleting fax after log: " & suniqueid & ", in module GenerateRcvdFaxLog(), error: " & RF2VBErr2String(lError)
                                       End If
                                    End If
                                    '---------------------------********************************--------------------------------
                                 End If 'check billinfo2, only log the fax if it is not ""
                              End If 'check getting fax info
                           End If 'check getting fax handle
                        End If 'filter out the ones that are DoneOK or DoneError
                     End If 'check getting fax status
281                  Sleep 100
282                  lError = RFVB_Clear(RFO_FAXLISTELEMENT_0, lFaxObj)
283                  lError = RFaxListGetNextElement(lFaxList, lFaxObj)
284               Wend 'Loop thru all incoming fax
285               RFaxCloseListHandle (lFaxList)
286               lFaxList = 0
               End If
            End If
287         lError = RFVB_Clear(RFO_USERLISTELEMENT_0, lUserObj)
288         lError = RFaxListGetNextElement(lUserList, lUserObj)
289      Wend 'loop thru all users

290      RFVB_Delete (lUserObj)
291      RFVB_Delete (lUserInfoObj)
292      RFVB_Delete (lFaxObj)
293      RFVB_Delete (lFaxInfoObj)
294      RFVB_Delete (lHistoryObj)
295      lUserObj = 0
296      lUserInfoObj = 0
297      lFaxObj = 0
298      lFaxInfoObj = 0
299      lHistoryObj = 0

300      RFaxCloseListHandle (lUserList)
301      lUserList = 0
302      RFaxCloseServerHandle (hServer)
303      hServer = 0
      Else
         '      DebugLog "Failed to connect to fax server: " + RFServer
304      rsData.Close
305      Set rsData = Nothing
306      m_TransactionConn.Close
307      Set m_TransactionConn = Nothing
308      GenerateRcvdFaxLog = "Failed to connect to fax server: " + RFServer
309      If (hServer <> 0) Then
310         RFaxCloseServerHandle (hServer)
         End If
         Exit Function
      End If  'Login server??
311   rsData.Close
312   Set rsData = Nothing
313   m_TransactionConn.Close
314   Set m_TransactionConn = Nothing
315   GenerateRcvdFaxLog = "transaction log for recieved faxes generated successfully"
      Exit Function

GenerateRcvdFaxLogErrHandler:
316   If (m_TransactionConn.Errors.Count > 0) Then
         '      ErrorLog "database error occured, in module: GenerateRcvdFaxLog. Error: " & m_TransactionConn.Errors.Item(0).Description
317      GenerateRcvdFaxLog = "database error occured, error line: " & Erl & ", in module: GenerateRcvdFaxLog. Error: " & m_TransactionConn.Errors.Item(0).Description
318      m_TransactionConn.Errors.Clear
      Else
'ErrorLog "error occured in module: GenerateRcvdFaxLog"
320      If Err.Number <> 0 Then
321         GenerateRcvdFaxLog = "error occured while generating received fax log, error line: " & Erl & ", in module: GenerateRcvdFaxLog, error: " & Err.Description
322         Err.Clear
         Else
323         GenerateRcvdFaxLog = "unknown error occured while generating received fax log, error line: " & Erl & ", in module: GenerateRcvdFaxLog"
         End If
      End If

324   If (Not (rsData Is Nothing)) Then
325      If (rsData.State <> adStateClosed) Then
326         rsData.CancelUpdate
327         rsData.Close
         End If
328      Set rsData = Nothing
      End If
329   If (Not (m_TransactionConn Is Nothing)) Then
330      If (m_TransactionConn.State <> adStateClosed) Then
331         m_TransactionConn.Cancel
332         m_TransactionConn.Close
         End If
333      Set m_TransactionConn = Nothing
      End If
334   RFVB_Delete (lUserObj)
335   RFVB_Delete (lUserInfoObj)
336   RFVB_Delete (lFaxObj)
337   RFVB_Delete (lFaxInfoObj)
338   RFVB_Delete (lHistoryObj)
339   If (lHistoryList <> 0) Then
340      RFaxCloseListHandle (lHistoryList)
      End If
341   If (lFaxList <> 0) Then
342      RFaxCloseListHandle (lFaxList)
      End If
343   If (lUserList <> 0) Then
344      RFaxCloseListHandle (lUserList)
      End If
345   If (hServer <> 0) Then
346      RFaxCloseServerHandle (hServer)
      End If

End Function

 

by: supunrPosted on 2003-08-25 at 21:14:08ID: 9221263

I am not sure if this is what you are after.  but say you have a recordset and you are not sure if the recordset exist or opened then...

if (not rs is nothing) then
   if (rs.state = adstateopen) then rs.close
   set rs = nothing
end if

you could do the same for connections.  but sometimes before you close recordsets you may want to update/cancelupdate and if before close connections, you may want to commit/rollback tansactions.

 

by: virus_patPosted on 2003-08-25 at 21:41:12ID: 9221358

Thanks for the reply!  I don't think part of the code is where the problem is, because when I check the log file, that part never got executed.  I believe its a memory leak in the API I am using, so I need a tool to track down and make sure where the leak memory so that I can report it to the API's tech support.

 

by: virus_patPosted on 2003-08-26 at 00:34:55ID: 9221957

By the way, the error in windows event viewer log is :
The COM+ Services DLL(comsvcs.dll) was unable to load because allocation of thread local storage failed.
...
Error Code = 0x80070008: Not enough storage is available to process this command.
...

 

by: GivenRandyPosted on 2003-08-26 at 03:03:11ID: 9222534

If you want the best tool for detecting memory leaks, check out Compuware (aka Numega) DevPartner:

http://www.compuware.com/products/devpartner/1969_ENG_HTML.htm

Not cheap, but well worth its price. We got the whole Studio and use all parts of it.

 

by: GivenRandyPosted on 2003-08-26 at 03:04:50ID: 9222541

p.s., you can get a free 14-day trial.

 

by: daffyduck14milPosted on 2003-08-26 at 04:04:50ID: 9222796

Not that this will help, but I agree wholeheartedly with GivenRandy. We also use the DevPartner studio tools at our company, and it is a great help in tracking down a lot of problems. Both at coding and at testing time. Also a great help in getting that lazy stuborn dumb programmer out of the company... (oops, there I said it, please ignore... :-)

On a more relevant note. ADO has a few known memory leaks. Most of the time it is due to an old DLL. Try to install the latest mdac (2.7 sp1 is the current one as of this date). I have had several memory leaks when using ADO, it stopped when I got the latest MDAC. Mdac's are located at http://www.microsoft.com/data.

 

by: GivenRandyPosted on 2003-08-26 at 05:54:14ID: 9223487

Good point, daffyduck14mil. You also want to make sure you have the latest Service Packs for Visual Basic.

For VB6, it is SP5:

http://msdn.microsoft.com/vstudio/downloads/updates/sp/vs6/sp5/default.aspx

Other updates:

http://msdn.microsoft.com/vbasic/downloads/updates/

 

by: virus_patPosted on 2003-08-26 at 18:33:45ID: 9229077

Thanks guys.
One more question, GivenRandy, about the VB service packs, the computer that I wrote the program with has SP5, but the computer that is running the program does not have VB installed, does it need any updates on the VB runtime files? Thanks in advance.

 

by: virus_patPosted on 2003-08-27 at 00:17:50ID: 9230265

Take a look at these 2 threads:
http://www.tek-tips.com/gviewthread.cfm/lev2/4/lev3/30/pid/787/qid/150767
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20328947.html

I think my problem is similar to these people, which is caused by repeatedly creating and closing a connection.  The solution they have is to call CoInit() and CoUninit() only at start and close, which applies to C++ only.  The problem with my application might be the same, but the way VB uses ADO doesn't have to call CoInit and CoUninit, maybe its called automatically, I am not sure.  The program is already in production and crashes every few days, Please HELP!!!

 

by: daffyduck14milPosted on 2003-08-27 at 00:56:19ID: 9230397

Hi,

On the surface there is no call to CoInitialize and CoUnitialize. VB does call CoCreateInstance to make an instance to your ADODB.Connection object. But this is all behind the curtain of the VB Runtime DLL. I would not dare to change anything in that general direction.

Your solution may well be to limit the number of connection objects you open and close during the natural life of your application. You can acomplish such a structure by implementing a Singleton pattern. A connection object being the object wrapped and singletoned. That will result in one connection object for your entire application, even if you create a new connection, it will return the (opened) connection object. But this might well be no option for your specific set-up since it would require a considerate amount of rewriting.

Thus, your only option is to limit connection object interaction by making sure a connection is only opened and closed once. But I think you already got such an idea from the two links you gave. Never the less, it does explain why my code don't have problems with this memory leak, since I only open a connection once, and keep it open. Legacy projects, they hurt pretty bad.

Grtz.&copy;

D.

 

by: virus_patPosted on 2003-08-27 at 01:48:39ID: 9230617

Thanks daffyduck14mil.
My application connects to the database and writes data to it every 15 mins, leaving the connection opened for days and weeks is not an option for me, :(
I've been search MSDN for this issue and found nothing, yet so many people have the same error message in the eventlog and the same problem, arghhhhhhh.
I am increasing the points to 400.  Does anyone have a workaround for this problem?

 

by: EDDYKTPosted on 2003-08-27 at 04:30:16ID: 9231356

I use GlobalMemoryStatus to detect memory leak, but you have to put inside your code to detect


One thing I suggest is to close your connection when you finished writing. Don't leave it open



Option Explicit
Private Type MEMORYSTATUS
    dwLength As Long
    dwMemoryLoad As Long
    dwTotalPhys As Long
    dwAvailPhys As Long
    dwTotalPageFile As Long
    dwAvailPageFile As Long
    dwTotalVirtual As Long
    dwAvailVirtual As Long
End Type
Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS)


Public Sub TakeMemorySnap(ByVal TempName As String)
Dim YourMemory As MEMORYSTATUS

    GlobalMemoryStatus YourMemory
   
    InsertLog TempName, "Total Phys: " & Format(YourMemory.dwTotalPhys, "#,# \b\y\t\e\s"), True
    InsertLog TempName, "Total Avail: " & Format(YourMemory.dwAvailPhys, "#,# \b\y\t\e\s"), True
    InsertLog TempName, "Total Page File: " & Format(YourMemory.dwTotalPageFile, "#,# \b\y\t\e\s"), True
    InsertLog TempName, "Avail PageFile: " & Format(YourMemory.dwAvailPageFile, "#,# \b\y\t\e\s"), True
    InsertLog TempName, "Total Virtual: " & Format(YourMemory.dwTotalVirtual, "#,# \b\y\t\e\s"), True
    InsertLog TempName, "Avail Virtual: " & Format(YourMemory.dwAvailVirtual, "#,# \b\y\t\e\s"), True

End Sub

Private Sub InsertLog(Reportname As String, Msg As String)
    Dim FileNo As Integer, tmpLen As Integer

    On Error Resume Next
    FileNo = FreeFile
    Open "dbfile" For Append Shared As #FileNo
    Print #FileNo, OneLine
    Close #FileNo
End Sub

 

by: GivenRandyPosted on 2003-08-27 at 05:46:07ID: 9231860

To update the target system with changes in the service pack, make a Package and Deployment Wizard installation with all the files included (it should do that by default).

 

by: virus_patPosted on 2003-08-28 at 19:18:22ID: 9245072

I'll try out the Compuware tool, thanks guys!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...