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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now