c# - What is the best method to handle connection string in windows form application? -


my c# application use dataset , tableadapters. generated form vs2008 gui tool.

example:

right click project - > add new item - > dataset

this method add connection string automatically app.config.

but hard corded method connection string. want change connection string in easy way. when used data set, connection string application property. there solution situation?

enter image description here

this connection string store in settings.designer.cs file

    namespace windowsformsapplication2.properties {       [global::system.runtime.compilerservices.compilergeneratedattribute()]     [global::system.codedom.compiler.generatedcodeattribute("microsoft.visualstudio.editors.settingsdesigner.settingssinglefilegenerator", "9.0.0.0")]     internal sealed partial class settings : global::system.configuration.applicationsettingsbase {          private static settings defaultinstance = ((settings)(global::system.configuration.applicationsettingsbase.synchronized(new settings())));          public static settings default {             {                 return defaultinstance;             }         }          [global::system.configuration.applicationscopedsettingattribute()]         [global::system.diagnostics.debuggernonusercodeattribute()]         [global::system.configuration.specialsettingattribute(global::system.configuration.specialsetting.connectionstring)]         [global::system.configuration.defaultsettingvalueattribute("data source=slcert\\sqlemk;initial catalog=testdatabase;integrated security=true")]         public string testdatabaseconnectionstring {             {                 return ((string)(this["testdatabaseconnectionstring"])); // connection string dataset's             }         }     } } 

app.config contains

<?xml version="1.0" encoding="utf-8" ?> <configuration>     <configsections>     </configsections>     <connectionstrings>         <add name="windowsformsapplication2.properties.settings.testdatabaseconnectionstring"             connectionstring="data source=slcert\sqlemk;initial catalog=testdatabase;integrated security=true"             providername="system.data.sqlclient" />     </connectionstrings> </configuration> 

i believe ask this, don't have manually change between local testing , production/test server.

you might want @ how to: transform web.config when deploying web application project

it's web.config instead of app.config same idea.

ps. vs 2010 , above


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -