Wednesday, 15 April 2015

c# - connectionStrings configSource in App.config not working -



c# - connectionStrings configSource in App.config not working -

i'm trying separate connection string app.config, , can't transformations web.config, thought may utilize configsource attribute point config file connection string in, doesn't seem working.

this works, app.config:

<?xml version="1.0" encoding="utf-8"?> <configuration> <configsections> <section name="entityframework" type="system.data.entity.internal.configfile.entityframeworksection, entityframework, version=5.0.0.0, culture=neutral, publickeytoken=*snip*" requirepermission="false" /> </configsections> <entityframework> <defaultconnectionfactory type="system.data.entity.infrastructure.localdbconnectionfactory, entityframework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultconnectionfactory> </entityframework> <connectionstrings> <add name="defaultconnection" providername="system.data.sqlclient" connectionstring="server=*snip*" /> </connectionstrings> </configuration>

but doesn't, app.config:

<?xml version="1.0" encoding="utf-8"?> <configuration> <configsections> <section name="entityframework" type="system.data.entity.internal.configfile.entityframeworksection, entityframework, version=5.0.0.0, culture=neutral, publickeytoken=*snip*" requirepermission="false" /> </configsections> <entityframework> <defaultconnectionfactory type="system.data.entity.infrastructure.localdbconnectionfactory, entityframework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultconnectionfactory> </entityframework> <connectionstrings configsource="connections.config" /> </configuration>

connections.config:

<connectionstrings> <add name="defaultconnection" providername="system.data.sqlclient" connectionstring="*snip*" /> </connectionstrings>

i'm looking simplest of solutions.

any ideas?

if added file yourself, build action (in file properties) may not have been set correctly.

the copy output directory alternative needs copy if newer or copy always ensure .config file ends in bin directory, otherwise not there , trying load configuration fail.

c# .net visual-studio-2012 connection-string

No comments:

Post a Comment