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

asked on

.Net WinForms Database Connections for Solution

I have a WinForms .Net solution that works.

Publishes to Network share with version and updates control.

I have been controlling whether it looks at the test sql server or live sql server by using a setting in the Solution Properties.

It's been suggested to me that maybe I culd use an xml file?

For instance this is used by our MS Access 2003 team.
	<Database>Assignment Control System_be</Database>

Open in new window

My problem is that the install of my application is different depending on the client pc being Win7, XP etc...

Suggestions? My IT Manager wants to be able to change the xml file locally and point to dev

This is my current properties
User generated image
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
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


 I have all the connections in my App.Config file.

There is an isProduction line right now that's hard coded...
            <setting name="isProduction" serializeAs="String">

Open in new window

I just want to get that from a 3 line xml file instead of actually IN the application.

Right now I'm consuming that in a CommonFunctions class file
    Public Shared Function ngAppConfig(ByVal i_key As String) As String
        Return ConfigurationManager.AppSettings(i_key)
    End Function

    Public Shared Function ngSqlConnectionString(ByVal live As Integer) As SqlConnection
        Dim objConn As SqlConnection = Nothing
        If live = 1 Then
            objConn = New SqlConnection(ConfigurationManager.ConnectionStrings("Accounting.My.MySettings.acsLive").ToString())
        ElseIf live = 2 Then
            objConn = New SqlConnection(ConfigurationManager.ConnectionStrings("acsJob").ToString())
            objConn = New SqlConnection(ConfigurationManager.ConnectionStrings("Accounting.My.MySettings.acsDev").ToString())
        End If
        Return objConn
    End Function

Open in new window

And on my forms vb code I have the connection set this way
 Using objConn As SqlConnection = ngSqlConnectionString(CInt(My.Settings.isProduction))
Do you compile the application in Debug for dev and in Release for production environment? If you do, you can use "#if debug" check to choose connection string based on current build type.
Sorry for slow getback

Here's the deal...
I really need to go to the user pc and in a Maintenance form (exists) log in as IT and set something to point to the DEV/Test database.
Used the example shown and set to hidden checkbox

If checked pass in live
pass in 0

I set it from an admin form