c# - how to add a custom configuration settings in the app.config? -
c# - how to add a custom configuration settings in the app.config? -
this question has reply here:
custom config section in app.config c# 3 answersi have app.config:
<?xml version="1.0" encoding="utf-8"?> <configuration> <configsections> <sectiongroup name="applicationsettings" type="system.configuration.applicationsettingsgroup, system, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089"> <section name="me.properties.settings" type="system.configuration.clientsettingssection, system, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" requirepermission="false" /> <section name="entityframework" type="system.data.entity.internal.configfile.entityframeworksection, entityframework, version=6.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" requirepermission="false" /> </sectiongroup> <section name="entityframework" type="system.data.entity.internal.configfile.entityframeworksection, entityframework, version=6.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" requirepermission="false" /> <connectionstrings> <add name="myconnectionstring01" connectionstring="...." /> <add name="myconnectionstring02" connectionstring="...." /> </connectionstrings> <applicationsettings> <me.properties.settings> <setting name="basedatosmedioacceso" serializeas="string"> <value>sqlserveref6</value> </setting> </me.properties.settings> </applicationsettings> <entityframework> <defaultconnectionfactory type="system.data.entity.infrastructure.sqlconnectionfactory, entityframework" /> <providers> <provider invariantname="system.data.sqlclient" type="system.data.entity.sqlserver.sqlproviderservices, entityframework.sqlserver" /> </providers> </entityframework> <startup> <supportedruntime version="v4.0" sku=".netframework,version=v4.5.1"/></startup> </configuration>
but add together kind of settings:
<databases> <add description="local" connectionstring="myconnectionstring01"/> <add description="local (test)" connectionstring="myconnectionstring02"/> </databases>
but don't know tu set configuration. have tried create config section, not work.
the thought have description easy read user , relate description connection string utilize entity framework.
thanks.
to add together generic custom key's can utilize following:
<configuration> <appsettings> <add key="local" value="myconnectionstring01" /> <add key="localtest" value="myconnectionstring02" /> </appsettings> </configuration>
to add together database connection strings utilize following:
<configuration> <connectionstrings> <add name="local" connectionstring="myconnectionstring01"/> <add name="localtest" connectionstring="myconnectionstring02"/> </connectionstrings> </configuration>
offhand, i'm not sure if spaces/special characters (i.e. "local (test)") allowed in key or name parameter. i've never seen utilize there. i'd utilize localtest instead. http://msdn.microsoft.com/en-us/library/ms254494(v=vs.110).aspx
c# app-config
Comments
Post a Comment