"In ASP.NET programming," writes Chad Braun-Duin, "database connection strings are stored in configuration files, and the standard way of getting your connection string from these files looks like this:"

ConfigurationManager.ConnectionStrings(AppName).ConnectionString

"Of course, this particular company (who will go nameless) took a different approach:"

    Public Shared Function GetConnectionString() As String
        'Dim sOleDb As String
        'Dim cn As OleDbConnection
        'Dim cmd As OleDbCommand
        'Dim dr As OleDbDataReader
        Dim returnConnString As String
        Dim sMethod, sColumns, sTableName As String
        sColumns = "DataLink, Platform, Login, Password, Server, Database"
        sTableName = "tblzApp"
        sMethod = ""
        If ConfigurationManager.AppSettings.Count > 0 Then
            sMethod = ConfigurationManager.AppSettings.GetKey(0)
        End If
        Try
            Select Case sMethod
                Case "ConnectionString"
                    returnConnString = ConfigurationManager.AppSettings(sMethod).ToString
                Case Else
                    Return sMethod
            End Select
            Return returnConnString
        Catch ex As Exception
            ex.Source &= "
DAL.GetConnectionString" Throw ex End Try End Function

"This is from a big company selling off-the-shelf software. The major atrocity here is that instead of simply getting the connection string by key ('ConnectionString' in this case), they first look it up by position. This makes no sense. Later, if the lookup-by-position works, then they get it by key."

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!