[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

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

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
jxharding
Asked:
jxharding
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
jxhardingAuthor Commented:
thanks!!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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