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.
<SQLConnection>
	<Server>ngsrvrdev\dev</Server>
	<Database>Assignment Control System_be</Database>
</SQLConnection>

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
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada 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

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

There is an isProduction line right now that's hard coded...
   <applicationSettings>
        <Accounting.My.MySettings>
            <setting name="isProduction" serializeAs="String">
                <value>0</value>
            </setting>

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())
        Else
            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.
CodeCruiser
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
else
pass in 0

I set it from an admin form