Solved

help me write a public class to return a connectionstring, because i have a connectionstring on every single page

Posted on 2006-07-05
2
208 Views
Last Modified: 2010-04-23
hi
how do other developers approach this?

(im migrating from 2003 to 2005 in the next few months)
i'd like to change my 2003 project
on each and every single page i declare:


 i'd like to write a function in a public class where i create a connectionstring.
currently on every single form i have, i declare
dim mySqlConnection As SqlConnection

and in the load section i do this
mySqlConnection = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString"))


could you pls help me write a sub or function where i could have this in a public class
and where i can call it from every page?

now when i convert from 2003 to 2005 i can just replace
mySqlConnection = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString"))
mySqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("Your connection string name").ConnectionString)


how do you do it?
thanks!

0
Comment
Question by:jxharding
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 17042124
If you just want to simplify the mechanism of retrieving your connection string you can use something like:

Public Class Settings
    Private Shared connString As String = String.Empty

    Public Shared ReadOnly Property ConnectionString() As String
        Get
            If connString = String.Empty Then
                connString = System.Configuration.ConfigurationManager.ConnectionStrings("Your connection string name").ConnectionString
            End If
            Return connString
        End Get
    End Property

End Class

Then use it like:

    Dim s As String = Settings.ConnectionString
0
 

Author Comment

by:jxharding
ID: 17042410
thanks!!
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

696 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