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
205 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
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DataGridView Events ? 3 45
Change Format on Data when exporting to Excel 4 32
Access to class from any project within a solution. 6 23
start a process from a service 3 21
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

785 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