Well, this may be just as crappy and inflexible as what you currently do, but here is the code we have been using without issue for the last few apps. We keep the db connection info in an ini so it can be pointed at either the test or production server by changing the ini.
This is code from the main form's load event:
'Get SQL Server database and server names from .ini
Open INI_FILE_PATH For Input As #1
Do While Not EOF(1)
'Read one line from the ini file
Input #1, strTemp
'Ignore case and leading whitespace
strTemp = UCase(Trim(strTemp))
'Check for blank lines or comment lines
If strTemp <> "" And Left(strTemp, 2) <> "//" Then
'Get the value and put it in the appropriate global variable
Select Case Left(strTemp, 4)
Case Is = "DATA"
gstrSQLDataSource = GetINIValue(strTemp)
Case Is = "INIT"
gstrSQLInitialCatalog = GetINIValue(strTemp)
Case Is = "LABE"
gstrLabelPrinter = GetINIValue(strTemp)
End Select
End If
Loop
Close #1
And here is the function code:
Private Function GetINIValue(strStringToParse As String)
Dim intStartingPoint As Integer, i As Integer, intAsciiCode As Integer
For i = 1 To Len(strStringToParse)
'Get the ascii code for the character
intAsciiCode = Asc(Mid(strStringToParse, i, 1))
'If it's not a space or alphanumeric character, replace it with a space
If intAsciiCode < 33 Or intAsciiCode > 126 Then Mid(strStringToParse, i, 1) = " "
Next i
'find the ":" in the string
intStartingPoint = InStr(1, strStringToParse, ":")
If intStartingPoint > 0 Then
'Get the value to the right of the colon
GetINIValue = Trim(Mid(strStringToParse, intStartingPoint + 1))
Else
GetINIValue = ""
End If
End Function
And here is what our ini file looks like:
//kwc.ini
//This configuration file specifies DB connection information used by applications
//Any lines beginning with // are treated as comments and will be ignored by the applications
//Test instance
//data source :servername\instancename
//initial catalog

bname
//Production instance
data source :servername\instancename
initial catalog

bname
//Label printer setup
label printer :\\printserver\printername