• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 411
  • Last Modified:

how do i create a public connection object in VB.net

HI

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
0
mackie1908
Asked:
mackie1908
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now