Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

Appsetting Key vs Connection Strings

When I took over a recent project there were WebConfig ConnectionStrings and AppSetting Key connection strings all over the place.

And many of them doing the same thing

So I consolidated into two functions

In the code at the bottom I have two functions
One points to AppSetting key the other to ConnectonStrings

I pass in a 1 or 0 that tells it whether live or dev.

My question is...is there a difference in the actual connection?

Most of my settings are on the vb side
Example

myGridView.DataSource = dt.Databind()

But here and there I have tags on the HTML Side
Example
<a id="clickElement" target="_blank" href="viewHtml.aspx?id=<%# Eval("EBQID")%>"
                                        onclick='showPopup(this.href);return(false);'>View</a>

Open in new window



So...do the AppSetting and the ConnectionString both accomplish the same thing? Everything below point to the same database...just whether it's on the live server or dev server.

I'd like to get down to just one function if there's no difference!


    'For applications that use Appsettings key
    Public Function ngSqlConnection(ByVal live As Integer) As SqlConnection
        Dim objConn As SqlConnection = Nothing
        If live = 1 Then
            objConn = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("strConn"))
        Else
            objConn = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("strDev"))
        End If
        Return objConn
    End Function


    'For connections that use connection string
    Public Function ngSqlConnectionString(ByVal live As Integer) As SqlConnection
        Dim objConn As SqlConnection = Nothing
        If live = 1 Then
            objConn = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("acsLive").ToString())
        Else
            objConn = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("acsDev").ToString())
        End If
        Return objConn
    End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Larry Brister

ASKER

CodeCruiser

So no penalty for dumping one of them right?
I would suggest sticking with the "connectionString" version. Some libraries (e.g. Enterprise Library) rely on this structure. I also find it a bit more intuitive (but that's probably just because I've been using it for so long. There is no performance difference in using one over the other.
Thanks