473,748 Members | 2,887 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.OutOfMem oryException when showing form

Baz
Hi.

I'm new to this VB.Net mullarkey, and I must say it is proving to be a very
trying experience. Here is the latest in a long line of problems:

The Scenario
=========

I am building an MDI application. The first thing it does is to pop up a
little logon form which gathers and authenticates an SQL Server
username/password. It then whacks these into a couple of global variables
so they are available for any subsequent database access. Here are the
declarations of those variables (they are simply in a regular module):

Friend gstrUserName As String
Friend gstrPassword As String

Now, I have another form which is launched from a menu on the mdi parent.
Here is the code which does that:

Private Sub mnuCountries_Cl ick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles mnuCountries.Cl ick

Dim frmCountry As New frmCountry

frmCountry.MdiP arent = Me
frmCountry.Show ()

End Sub

BUT, one of the first things frmCountry does is to grab itself a middle-tier
object (a class) so as to populate the lists in some combo boxes, and in
order to do this it needs to pass in the SQL Server credentials mentioned
above i.e. it needs to refer to the two global variables. Hence, I have a
Form Load event procedure as follows (where cfrMain is a user control I have
created which has the combo boxes on it):

Private Sub frmCountry_Load (ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load

Dim objCountries As New midCountry

With objCountries
.UserName = gstrUserName
.Password = gstrPassword
End With
cfrMain.DataSou rce = objCountries

End Sub

Please feel free to criticise/comment on the general approach I have adopted
here, or any specifics in these code snippets (I am, after all, trying to
learn). However, the particular problem I have is that the statement
frmCountry.Show () throws a System.OutOfMem oryException error. HOWEVER, and
here's the weird bit, if I comment out the following two statements in
frmCountry_Load , then frmCountry shows OK:

.UserName = gstrUserName
.Password = gstrPassword

frmCountry also shows OK if I replace the references to the global variables
with literals e.g.

.UserName = "myuser"
.Password = "mypassword "

It also shows OK if it's not a child form.

So what's going on here? Why does something as apparently trivial as
referencing a couple of global variables result in an out-of-memory error?
And what can I do about it? And should I give up on the mdi application (a
trawl through Google groups shows a LOT of out-of-memory problems when
showing a child form, but no answers that I can find)?

Thanks for listening!

Baz


Nov 20 '05 #1
4 4185
Hi Baz

The first thing I noticed was that you define a variable with the same name
as a class. Whilst not forbidden, I would personally avoid this as it can
cause no end of problems when referencing the instance.

I would be inclined to change your click handler to something like

<code>
Private Sub mnuCountries_Cl ick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles mnuCountries.Cl ick

Dim frm As New frmCountry

frm.MdiParent = Me
frm.Show()

End Sub
</code>

then there is no confusion regarding which object is being referenced. This
may even resolve your problem.

HTH

Charles
"Baz" <bc**@clara.co. uk> wrote in message
news:10******** ********@lotis. uk.clara.net...
Hi.

I'm new to this VB.Net mullarkey, and I must say it is proving to be a very trying experience. Here is the latest in a long line of problems:

The Scenario
=========

I am building an MDI application. The first thing it does is to pop up a
little logon form which gathers and authenticates an SQL Server
username/password. It then whacks these into a couple of global variables
so they are available for any subsequent database access. Here are the
declarations of those variables (they are simply in a regular module):

Friend gstrUserName As String
Friend gstrPassword As String

Now, I have another form which is launched from a menu on the mdi parent.
Here is the code which does that:

Private Sub mnuCountries_Cl ick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles mnuCountries.Cl ick

Dim frmCountry As New frmCountry

frmCountry.MdiP arent = Me
frmCountry.Show ()

End Sub

BUT, one of the first things frmCountry does is to grab itself a middle-tier object (a class) so as to populate the lists in some combo boxes, and in
order to do this it needs to pass in the SQL Server credentials mentioned
above i.e. it needs to refer to the two global variables. Hence, I have a
Form Load event procedure as follows (where cfrMain is a user control I have created which has the combo boxes on it):

Private Sub frmCountry_Load (ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load

Dim objCountries As New midCountry

With objCountries
.UserName = gstrUserName
.Password = gstrPassword
End With
cfrMain.DataSou rce = objCountries

End Sub

Please feel free to criticise/comment on the general approach I have adopted here, or any specifics in these code snippets (I am, after all, trying to
learn). However, the particular problem I have is that the statement
frmCountry.Show () throws a System.OutOfMem oryException error. HOWEVER, and here's the weird bit, if I comment out the following two statements in
frmCountry_Load , then frmCountry shows OK:

.UserName = gstrUserName
.Password = gstrPassword

frmCountry also shows OK if I replace the references to the global variables with literals e.g.

.UserName = "myuser"
.Password = "mypassword "

It also shows OK if it's not a child form.

So what's going on here? Why does something as apparently trivial as
referencing a couple of global variables result in an out-of-memory error?
And what can I do about it? And should I give up on the mdi application (a trawl through Google groups shows a LOT of out-of-memory problems when
showing a child form, but no answers that I can find)?

Thanks for listening!

Baz



Nov 20 '05 #2
Hi Baz

The first thing I noticed was that you define a variable with the same name
as a class. Whilst not forbidden, I would personally avoid this as it can
cause no end of problems when referencing the instance.

I would be inclined to change your click handler to something like

<code>
Private Sub mnuCountries_Cl ick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles mnuCountries.Cl ick

Dim frm As New frmCountry

frm.MdiParent = Me
frm.Show()

End Sub
</code>

then there is no confusion regarding which object is being referenced. This
may even resolve your problem.

HTH

Charles
"Baz" <bc**@clara.co. uk> wrote in message
news:10******** ********@lotis. uk.clara.net...
Hi.

I'm new to this VB.Net mullarkey, and I must say it is proving to be a very trying experience. Here is the latest in a long line of problems:

The Scenario
=========

I am building an MDI application. The first thing it does is to pop up a
little logon form which gathers and authenticates an SQL Server
username/password. It then whacks these into a couple of global variables
so they are available for any subsequent database access. Here are the
declarations of those variables (they are simply in a regular module):

Friend gstrUserName As String
Friend gstrPassword As String

Now, I have another form which is launched from a menu on the mdi parent.
Here is the code which does that:

Private Sub mnuCountries_Cl ick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles mnuCountries.Cl ick

Dim frmCountry As New frmCountry

frmCountry.MdiP arent = Me
frmCountry.Show ()

End Sub

BUT, one of the first things frmCountry does is to grab itself a middle-tier object (a class) so as to populate the lists in some combo boxes, and in
order to do this it needs to pass in the SQL Server credentials mentioned
above i.e. it needs to refer to the two global variables. Hence, I have a
Form Load event procedure as follows (where cfrMain is a user control I have created which has the combo boxes on it):

Private Sub frmCountry_Load (ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load

Dim objCountries As New midCountry

With objCountries
.UserName = gstrUserName
.Password = gstrPassword
End With
cfrMain.DataSou rce = objCountries

End Sub

Please feel free to criticise/comment on the general approach I have adopted here, or any specifics in these code snippets (I am, after all, trying to
learn). However, the particular problem I have is that the statement
frmCountry.Show () throws a System.OutOfMem oryException error. HOWEVER, and here's the weird bit, if I comment out the following two statements in
frmCountry_Load , then frmCountry shows OK:

.UserName = gstrUserName
.Password = gstrPassword

frmCountry also shows OK if I replace the references to the global variables with literals e.g.

.UserName = "myuser"
.Password = "mypassword "

It also shows OK if it's not a child form.

So what's going on here? Why does something as apparently trivial as
referencing a couple of global variables result in an out-of-memory error?
And what can I do about it? And should I give up on the mdi application (a trawl through Google groups shows a LOT of out-of-memory problems when
showing a child form, but no answers that I can find)?

Thanks for listening!

Baz



Nov 20 '05 #3
Baz
Thx for the reply Charles. Good point about the naming.

I have changed the design so that UserName and Password, instead of being
properties of the middle tier object, are instead arguments of it's methods.
This involved moving the code that references the global variables, so that
it is now done by the user control, cfrMain, rather than in the Load event
of the form. It still gets done when the form loads, but it's a couple of
calls further down the stack, as it were. And...the problem went away.

Seems to be (yet another) bug in .Net. A few days ago I wasted a couple of
hours discovering the unreliability of setting the SelectedIndex for a bound
combo box to -1. Is programming in VB.Net always this frustrating?

Baz

"Charles Law" <bl***@nowhere. com> wrote in message
news:uP******** ******@TK2MSFTN GP12.phx.gbl...
Hi Baz

The first thing I noticed was that you define a variable with the same name as a class. Whilst not forbidden, I would personally avoid this as it can
cause no end of problems when referencing the instance.

I would be inclined to change your click handler to something like

<code>
Private Sub mnuCountries_Cl ick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles mnuCountries.Cl ick

Dim frm As New frmCountry

frm.MdiParent = Me
frm.Show()

End Sub
</code>

then there is no confusion regarding which object is being referenced. This may even resolve your problem.

HTH

Charles
"Baz" <bc**@clara.co. uk> wrote in message
news:10******** ********@lotis. uk.clara.net...
Hi.

I'm new to this VB.Net mullarkey, and I must say it is proving to be a

very
trying experience. Here is the latest in a long line of problems:

The Scenario
=========

I am building an MDI application. The first thing it does is to pop up a little logon form which gathers and authenticates an SQL Server
username/password. It then whacks these into a couple of global variables so they are available for any subsequent database access. Here are the
declarations of those variables (they are simply in a regular module):

Friend gstrUserName As String
Friend gstrPassword As String

Now, I have another form which is launched from a menu on the mdi parent. Here is the code which does that:

Private Sub mnuCountries_Cl ick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles mnuCountries.Cl ick

Dim frmCountry As New frmCountry

frmCountry.MdiP arent = Me
frmCountry.Show ()

End Sub

BUT, one of the first things frmCountry does is to grab itself a

middle-tier
object (a class) so as to populate the lists in some combo boxes, and in
order to do this it needs to pass in the SQL Server credentials mentioned above i.e. it needs to refer to the two global variables. Hence, I have a Form Load event procedure as follows (where cfrMain is a user control I

have
created which has the combo boxes on it):

Private Sub frmCountry_Load (ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load

Dim objCountries As New midCountry

With objCountries
.UserName = gstrUserName
.Password = gstrPassword
End With
cfrMain.DataSou rce = objCountries

End Sub

Please feel free to criticise/comment on the general approach I have

adopted
here, or any specifics in these code snippets (I am, after all, trying to learn). However, the particular problem I have is that the statement
frmCountry.Show () throws a System.OutOfMem oryException error. HOWEVER,

and
here's the weird bit, if I comment out the following two statements in
frmCountry_Load , then frmCountry shows OK:

.UserName = gstrUserName
.Password = gstrPassword

frmCountry also shows OK if I replace the references to the global

variables
with literals e.g.

.UserName = "myuser"
.Password = "mypassword "

It also shows OK if it's not a child form.

So what's going on here? Why does something as apparently trivial as
referencing a couple of global variables result in an out-of-memory error? And what can I do about it? And should I give up on the mdi application

(a
trawl through Google groups shows a LOT of out-of-memory problems when
showing a child form, but no answers that I can find)?

Thanks for listening!

Baz




Nov 20 '05 #4
Baz
Thx for the reply Charles. Good point about the naming.

I have changed the design so that UserName and Password, instead of being
properties of the middle tier object, are instead arguments of it's methods.
This involved moving the code that references the global variables, so that
it is now done by the user control, cfrMain, rather than in the Load event
of the form. It still gets done when the form loads, but it's a couple of
calls further down the stack, as it were. And...the problem went away.

Seems to be (yet another) bug in .Net. A few days ago I wasted a couple of
hours discovering the unreliability of setting the SelectedIndex for a bound
combo box to -1. Is programming in VB.Net always this frustrating?

Baz

"Charles Law" <bl***@nowhere. com> wrote in message
news:uP******** ******@TK2MSFTN GP12.phx.gbl...
Hi Baz

The first thing I noticed was that you define a variable with the same name as a class. Whilst not forbidden, I would personally avoid this as it can
cause no end of problems when referencing the instance.

I would be inclined to change your click handler to something like

<code>
Private Sub mnuCountries_Cl ick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles mnuCountries.Cl ick

Dim frm As New frmCountry

frm.MdiParent = Me
frm.Show()

End Sub
</code>

then there is no confusion regarding which object is being referenced. This may even resolve your problem.

HTH

Charles
"Baz" <bc**@clara.co. uk> wrote in message
news:10******** ********@lotis. uk.clara.net...
Hi.

I'm new to this VB.Net mullarkey, and I must say it is proving to be a

very
trying experience. Here is the latest in a long line of problems:

The Scenario
=========

I am building an MDI application. The first thing it does is to pop up a little logon form which gathers and authenticates an SQL Server
username/password. It then whacks these into a couple of global variables so they are available for any subsequent database access. Here are the
declarations of those variables (they are simply in a regular module):

Friend gstrUserName As String
Friend gstrPassword As String

Now, I have another form which is launched from a menu on the mdi parent. Here is the code which does that:

Private Sub mnuCountries_Cl ick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles mnuCountries.Cl ick

Dim frmCountry As New frmCountry

frmCountry.MdiP arent = Me
frmCountry.Show ()

End Sub

BUT, one of the first things frmCountry does is to grab itself a

middle-tier
object (a class) so as to populate the lists in some combo boxes, and in
order to do this it needs to pass in the SQL Server credentials mentioned above i.e. it needs to refer to the two global variables. Hence, I have a Form Load event procedure as follows (where cfrMain is a user control I

have
created which has the combo boxes on it):

Private Sub frmCountry_Load (ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load

Dim objCountries As New midCountry

With objCountries
.UserName = gstrUserName
.Password = gstrPassword
End With
cfrMain.DataSou rce = objCountries

End Sub

Please feel free to criticise/comment on the general approach I have

adopted
here, or any specifics in these code snippets (I am, after all, trying to learn). However, the particular problem I have is that the statement
frmCountry.Show () throws a System.OutOfMem oryException error. HOWEVER,

and
here's the weird bit, if I comment out the following two statements in
frmCountry_Load , then frmCountry shows OK:

.UserName = gstrUserName
.Password = gstrPassword

frmCountry also shows OK if I replace the references to the global

variables
with literals e.g.

.UserName = "myuser"
.Password = "mypassword "

It also shows OK if it's not a child form.

So what's going on here? Why does something as apparently trivial as
referencing a couple of global variables result in an out-of-memory error? And what can I do about it? And should I give up on the mdi application

(a
trawl through Google groups shows a LOT of out-of-memory problems when
showing a child form, but no answers that I can find)?

Thanks for listening!

Baz




Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2317
by: solomon | last post by:
Hi, I have installed VS.Net(Ver:7.0.9466) & .Net_Frameword_1.0 (Ver: 1.0.3705). Until recently, I could develop and run applications using the IDE. A couple of days ago, I downloaded a sample application (remoting example) that required .Net_Framework_1.1. Since then I can only run console apps. If I try to run a windows app with only a form, I get the following error message:
1
10067
by: king solomon | last post by:
Hi, I have installed VS.Net(Ver:7.0.9466) & .Net_Frameword_1.0 (Ver: 1.0.3705). Until recently, I could develop and run applications using the VS.IDE. A couple of days ago, I downloaded a sample application (remoting example) that required .Net_Framework_1.1. Since then I can only run console apps. If I try to run a windows app with only a form, I get the following error message:
0
2776
by: Per Bergland | last post by:
After many woes, I finally managed to get a stack dump of my System Service (written in C#) that insists on crashing when launched at system boot time (see below on how to get this dump - I couldn't find any info on how to do this). Here's the stack trace from cordbg: Unhandled exception generated: (0x04719c94) <System.Runtime.Remoting.RemotingException> _className=<null> _exceptionMethod=<null>
1
3448
by: Ripul Handa | last post by:
Hi We are running IIS 5.0 cluster with cisco local director. We are running a website on 2 webservers and I have been observing that from past few days we have are getting this error message of and on Error Messag Remote IP:66.122.242.6 Host:216.211.212.2
1
4986
by: SMG - Idealake | last post by:
Hi all, I am getting following error on my error, what could be the reason? Exception of type System.OutOfMemoryException was thrown. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.OutOfMemoryException: Exception of type System.OutOfMemoryException was thrown.
2
333
by: Baz | last post by:
Hi. I'm new to this VB.Net mullarkey, and I must say it is proving to be a very trying experience. Here is the latest in a long line of problems: The Scenario ========= I am building an MDI application. The first thing it does is to pop up a little logon form which gathers and authenticates an SQL Server
1
3898
by: Ashkan Daie | last post by:
Hi All, When trying to install a performance counter via InstallUtil I get the following exception: Creating performance counter category Enterprise Library Caching. An exception occurred during the Install phase. System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was
2
1627
by: ari | last post by:
I have a small form that comprises a toolbar, a treeview and a status bar. Everything was working fine until I decided to add a new button to the toolbar - and I decided for appearances sake to add a separator button to distance the new button from the old ones. When I do "show" on the form (which is an mdi-child) I get the following exception: System.OutOfMemoryException occurred in system.windows.forms.dll
8
12566
by: =?Utf-8?B?UGlnZ3k=?= | last post by:
Hi to all, I am getting this System.OutOfMemoryException calling the Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(<stream>,<Obj>) method. The type of <streamis IO.MemoryStream =====Exception: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4606
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.