473,546 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Usage of global sqlconnection throughout my project

Hi all,

I have a question/problem concerning usage of my sqlconnection throughout my
program.
In my main form (frmMain) I defined an sqlconnection (I've set the
connection public so that I can open & close the connection from everywhere
in my app).
My main form is an mdi parent which contains several mdi-childs.
To open and close the sqlconnection in an mdi-child i use the following:

((frmMain)this. mdiparent).sqlc onnection.open( );
((frmMain)this. mdiparent).sqlc onnection.close ();

But this works for an mdi-child. Now I want to use this sqlconnection within
a form that I show as modal, let me explain this a bit further:
I have an mdi-child open, from there I want to open a small form (by
..ShowModal()) and in that form I must open and close the sqlconnection to
save my in that form edited data.

Can somebody help me how to address my sqlconnection from my frmMain in this
form that is showed modal?

Thank you for helping me out.
Kind regards,
Tom.

Nov 16 '05 #1
4 5171
Offhand I think you'd have to pass a reference either to the connection or
to frmMain to the constructor of the modal form, or else send it to a public
property of the modal form before calling ShowDialog() on it.

For globally available stuff like this I tend to prefer using a class of
static members rather than relying on it being in a top level form. Then
it's just a matter of something like Globals.DBConne ction.Open(),
Globals.DBConne ction.Close(), etc. and it works the same no matter where you
call it from.

--Bob

"The Coolest Dolphin" <Th************ ***@discussions .microsoft.com> wrote in
message news:13******** *************** ***********@mic rosoft.com...
Hi all,

I have a question/problem concerning usage of my sqlconnection throughout
my
program.
In my main form (frmMain) I defined an sqlconnection (I've set the
connection public so that I can open & close the connection from
everywhere
in my app).
My main form is an mdi parent which contains several mdi-childs.
To open and close the sqlconnection in an mdi-child i use the following:

((frmMain)this. mdiparent).sqlc onnection.open( );
((frmMain)this. mdiparent).sqlc onnection.close ();

But this works for an mdi-child. Now I want to use this sqlconnection
within
a form that I show as modal, let me explain this a bit further:
I have an mdi-child open, from there I want to open a small form (by
.ShowModal()) and in that form I must open and close the sqlconnection to
save my in that form edited data.

Can somebody help me how to address my sqlconnection from my frmMain in
this
form that is showed modal?

Thank you for helping me out.
Kind regards,
Tom.

Nov 16 '05 #2
"The Coolest Dolphin" <Th************ ***@discussions .microsoft.com>
wrote:
Can somebody help me how to address my
sqlconnection from my frmMain in this form
that is showed modal?


Either pass the SqlConnection to the modal form's constructor, or
declare the SqlConnection as 'static' so that no instance of the
parent form is required.

P.
Nov 16 '05 #3
Thank you Bob & Paul for helping me out.

I will use and try both options.

Kind regards,
Tom.

"The Coolest Dolphin" wrote:
Hi all,

I have a question/problem concerning usage of my sqlconnection throughout my
program.
In my main form (frmMain) I defined an sqlconnection (I've set the
connection public so that I can open & close the connection from everywhere
in my app).
My main form is an mdi parent which contains several mdi-childs.
To open and close the sqlconnection in an mdi-child i use the following:

((frmMain)this. mdiparent).sqlc onnection.open( );
((frmMain)this. mdiparent).sqlc onnection.close ();

But this works for an mdi-child. Now I want to use this sqlconnection within
a form that I show as modal, let me explain this a bit further:
I have an mdi-child open, from there I want to open a small form (by
.ShowModal()) and in that form I must open and close the sqlconnection to
save my in that form edited data.

Can somebody help me how to address my sqlconnection from my frmMain in this
form that is showed modal?

Thank you for helping me out.
Kind regards,
Tom.

Nov 16 '05 #4
actually, .NET uses connection pooling, so all you need is to have the
same connection string in all the connection instances you want to share
and it'll use the same connection in its internals

The Coolest Dolphin wrote:
Thank you Bob & Paul for helping me out.

I will use and try both options.

Kind regards,
Tom.

"The Coolest Dolphin" wrote:

Hi all,

I have a question/problem concerning usage of my sqlconnection throughout my
program.
In my main form (frmMain) I defined an sqlconnection (I've set the
connection public so that I can open & close the connection from everywhere
in my app).
My main form is an mdi parent which contains several mdi-childs.
To open and close the sqlconnection in an mdi-child i use the following:

((frmMain)thi s.mdiparent).sq lconnection.ope n();
((frmMain)thi s.mdiparent).sq lconnection.clo se();

But this works for an mdi-child. Now I want to use this sqlconnection within
a form that I show as modal, let me explain this a bit further:
I have an mdi-child open, from there I want to open a small form (by
.ShowModal( )) and in that form I must open and close the sqlconnection to
save my in that form edited data.

Can somebody help me how to address my sqlconnection from my frmMain in this
form that is showed modal?

Thank you for helping me out.
Kind regards,
Tom.

Nov 16 '05 #5

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

Similar topics

9
2367
by: Tony Johansson | last post by:
Hello! I know it's bad design to use global variables. I just want to ask a question about them. Is global variables and global static variables the same. These are define outside any function at the top of the a file where you have them. //Tony
4
9315
by: RD | last post by:
I opened a connection to the database in the login form. Now in another form I tried to insert values to a table. But the connection is not available in the form. How can I make the connection global to all forms? Where I can declare global variables?( Like in VB standard module) Thanks RD
4
2748
by: Mark | last post by:
OK. Here we go. I have an ASP.NET application that does many hits to a SQL Server DB on a separate server. When I first created this application (2 years ago) and was very new to ASP/ASP.NET, to make the SQL connection string global throughout the application I created a .vb file within the application project and declared a public...
3
3005
by: Robert Walter | last post by:
I want to user the Page method LoadControl inside the Global.asax.cs but when I instantiate a page and try it I get the following error... System.NullReferenceException: Object reference not set to an instance of an object. at System.Web.UI.UserControlParser.GetCompiledUserControlType(String virtualPath, String inputFile, HttpContext...
4
1466
by: RC | last post by:
I'm trying to get an idea of the amount of memory is being used by my ASP.NET application. Here's what I did: I rebooted my machine and fired up VS.NET 2003, opened the project in question (without running it), then opened Task Manager (machine is Win2000 Pro). Task Manager showed aspnet_wp.exe as using about 21,000K. I then ran the...
22
1641
by: UJ | last post by:
How do I create an instance of a class that is accessible to all classes/forms in my project? I already have a startup module and I was thinking putting stuff in there and then accessing it through there. I need it for things like db connections, security manager, general db functions, ..... Any help would be appreciated..... UJ.
6
12379
by: Greg Smith | last post by:
Is it possible to declare a global constant? I would like to have a constant visible throughout the application but I can't get the syntax correct to make it global. Any help is greatly appreciated.
3
4026
by: rhyme2ri2 | last post by:
Hi! I want to use some variables throughout my VC#.net windows based application........... How can i declare global variables that will work throughout my project... -Regards
7
1822
by: twang090 | last post by:
I find in other team member's project, they are referencing a type in following format " public static global::ErrorReport.Description Description = new global::ErrorReport.Description(); " I do not understand the usage of "global" here, could anyone please clarify its usage and what benift of using that. Thanks in advance.
0
7435
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...
0
7947
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...
1
7461
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...
0
7792
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...
1
5360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
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
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.