Avatar of Larry Brister
Larry Brister
Flag 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
Visual Basic.NET.NET ProgrammingMicrosoft Development

Avatar of undefined
Last Comment
Larry Brister

8/22/2022 - Mon
Éric Moreau

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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))
Nasir Razzaq

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.
Larry Brister

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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Larry Brister

Used the example shown and set to hidden checkbox

If checked pass in live
pass in 0

I set it from an admin form