1 Attachment(s)
[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.
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