asp.net - using connectionstring from web.config instead of app.config -


i have class library project in i've added dataset talks sql server. output of project consumed web application project. intend put connection string in web application project.

did couple of things. in order make adapter use different connection string, had come across this. found doing following convenient:

dim adapter new myreqeusttableadapter() adapter.connection.connectionstring = smyconnectionstring 

then tried taking connection string configuration (app.config) kind of simulate . added section manually key "myconstr". ideas like:

smyconnectionstring = configurationmanager.connectionstring("myconstr").connectionstring 

but intellisense couldn't not detect configurationmanager. had add appropriate reference project.

next added connection string via settings designer web application project. gave above key referencing it. above statment seems throw null reference exception.

suppose have created class library. in you've defined settings property goes like:

properties.settings.default.projectname 

visual studio might auto generate configuration follows:

(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="mydllproject.properties.settings" type="system.configuration.clientsettingssection, system, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" requirepermission="false" />         </sectiongroup>     </configsections>     <applicationsettings>         <mydllproject.properties.settings>             <setting name="projectname" serializeas="string">                 <value>mydllproject</value>             </setting>         </mydllproject.properties.settings>     </applicationsettings> </configuration> 

now add assembly project. , access settings, you'd mydllproject value. in spite of adding configuration. why? because when assembly generated kind of written it. , code written such in absence of configuration override use defined in app.config @ time of generation.

now in target project, add necessary sections in configuration file in following pattern

<?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" >             <!-- start: copied app.config of class library -->             <section name="mydllproject.properties.settings"                  type="system.configuration.clientsettingssection, system, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" requirepermission="false"                  />             <!-- end: copied app.config of class library -->              <!-- other sections may follow -->         </sectiongroup>      </configsections>      <applicationsettings>         <!-- remember maintain same order how defined in sectiongroup -->          <!-- start: copied app.config of class librarly -->         <mydllproject.properties.settings>             <setting name="projectname" serializeas="string">                 <value>consoleprojectb</value>             </setting>         </mydllproject.properties.settings>         <!-- end: copied app.config of class library -->          <!-- other configurations settings may follow -->     </applicationsettings> </configuration> 

thats it.

here small project sample i've linked same: http://sdrv.ms/16kspef


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -