Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

Using the same connection over many forms

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dani - 27 Sep 2004 23:01 GMT
Hi,
I'm writing a client-server winfroms application, I've notice that every
time I use the wizard to create a bound datagrid, I create a new
sqlconnection.
I wish to create one connection in the main form, and use it in the rest.
(b/c changing something in the connection string - like pwd user or db will
make me go over all the classes now, and find all the connections the wizards
creatred)
what is the best way to do it ?
Regards,
Dani
Sijin Joseph - 29 Sep 2004 09:21 GMT
I define the connection string in either the application config file
(app.config) or the registry and then use a class which exposes a static
method that returns the connection string.

For e.g.

public class Settings
{
    public static ConnectionString
    {
        get
        {
            //Get the connection string either by using registry or by
using ConfigurationSettings.AppSettings class
        }
    }
}

Now in all the classes where i need a connection i simply use

SqlConnection conn = new SqlConnection(Settings.ConnectionString);

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> Hi,
> I'm writing a client-server winfroms application, I've notice that every
[quoted text clipped - 7 lines]
> Regards,
> Dani

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.