?
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
Medium Priority
?
209 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month12 days, 19 hours left to enroll

777 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