how do i create a public connection object in

Posted on 2006-05-04
Last Modified: 2008-03-10

I hav an MDI that  currently has about twenty forms and is expanding as needs go on and the spec of the sofware is changed. the functionality of the forms is fine no problems but each form has its own connection object the the form uses to connect to the database to read and write. what is bothering me about this is that when the time come for ditribution of the software i am going to have to change the connection string in each and every form to get them to work. is there a way of creating a public class/sub or function that all the forms can use to connect to the database that can be changed without affecting the forms.

cheers Mackie1908
Question by:mackie1908
    LVL 52

    Accepted Solution

    The simplest way is probably to create a class with a Shared method that returns the connection string (either hard-coded or from the app.config, or wherever):

        Class DbUtilities
            Public Shared Function ConnectionString() As String
                Return "Your connection string"
            End Function
        End Class

    That way you only have to change it in one place and will be accessible from all your forms.
    LVL 4

    Expert Comment


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now