Results 1 to 2 of 2

Thread: [RESOLVED] System.OutOfMemoryException

  1. #1

    Thread Starter
    Addicted Member riechan's Avatar
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    254

    Resolved [RESOLVED] System.OutOfMemoryException

    Hi guys. Anyone know how to solve this error?

    Code:
    An unhandled exception of type 'System.OutOfMemoryException' occurred in system.windows.forms.dll
    
    Additional information: Error creating window handle.
    It appeared when I was loading a child form (frmPublisher) from the MDI form. I'm guessing this has something to do with the loaded form being overloaded or something? This didn't kind of error didn't happen when frmPublisher's only opened the database connection once (during the Load event). I modified the code to make sure that frmPublisher's subs only opened the connection when needed, and I got this error.

    By the way, I'm opening the form via singleton method.

    Attached is the code from the frmPublisher.
    Attached Files Attached Files
    ====================
    ほんとにどもありがとう!

    Rie Ishida

  2. #2

    Thread Starter
    Addicted Member riechan's Avatar
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    254

    Re: System.OutOfMemoryException

    Sorry. Thread resolved. Something wrong with the frmPublisher's load event.

    Code:
    Original code:
        Private Sub frmPublisherManager_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            dbConn.ConnectionString = "Integrated Security=SSPI; Initial Catalog=CBIS; Persist Security Info=False;"
    
            ...
    
            'display data from the database into the text fields and datagrid
            If dbDsetPublisherManager.Tables(0).Rows.Count > 0 Then
                dbConn.Open()
    
                'initially populate the dataset
                dbAdpPublisherManager = New SqlClient.SqlDataAdapter("SELECT * from Publisher", dbConn)
                dbDsetPublisherManager = New DataSet
                dbAdpPublisherManager.Fill(dbDsetPublisherManager, "Publisher")
    
                FillFields()
                btnFirst.Enabled = False
                btnPrevious.Enabled = False
    
                dgPublisher.DataSource = dbDsetPublisherManager
                dgPublisher.DataMember = "Publisher"
            ElseIf dbDsetPublisherManager.Tables(0).Rows.Count = 0 Then
                MsgBox("There are no available publisher records. Click the" & vbCrLf & "[Add Entry] button to start adding records.", MsgBoxStyle.Information, "No Available Records")
            End If
    
            're-initilize the flags as FALSE
            addflag = False
            editflag = False
    
            dbConn.Close()
    
        End Sub
    Code:
    Revised code:
        Private Sub frmPublisherManager_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            dbConn.ConnectionString = "Integrated Security=SSPI; Initial Catalog=CBIS; Persist Security Info=False;"
            dbConn.Open()
    
            'initially populate the dataset
            dbAdpPublisherManager = New SqlClient.SqlDataAdapter("SELECT * from Publisher", dbConn)
            dbDsetPublisherManager = New DataSet
            dbAdpPublisherManager.Fill(dbDsetPublisherManager, "Publisher")
    
            ...
    
            'display data from the database into the text fields and datagrid
            If dbDsetPublisherManager.Tables(0).Rows.Count > 0 Then
                FillFields()
                btnFirst.Enabled = False
                btnPrevious.Enabled = False
    
                dgPublisher.DataSource = dbDsetPublisherManager
                dgPublisher.DataMember = "Publisher"
            ElseIf dbDsetPublisherManager.Tables(0).Rows.Count = 0 Then
                MsgBox("There are no available publisher records. Click the" & vbCrLf & "[Add Entry] button to start adding records.", MsgBoxStyle.Information, "No Available Records")
            End If
    
            're-initilize the flags as FALSE
            addflag = False
            editflag = False
    
            dbConn.Close()
    
        End Sub
    ====================
    ほんとにどもありがとう!

    Rie Ishida

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