Click here to Skip to main content
13,355,335 members (72,440 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
How to write connection string in web.config file using asp.net,

i just applied this code:

<configuration>
	<configsections>
    
        <add name="conn" connectionstring="Data Source=TEKPC26\SQLEXPRESS; <br mode=" hold=" />                       AttachDbFilename=registration.mdf; <br mode=" />
</configsections>
</configuration>


but getting one error!
"The element 'configSections' has invalid child element 'add'. List of possible elements expected: 'section, sectionGroup'.
Posted 2-Nov-11 19:59pm
Updated 2-Nov-11 20:03pm
P.Salini14.9K
v4
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Place in this way
You need to place it in configuration tag and outside configsections tag

<connectionStrings>
        <add name="ConnectionString" providerName="System.Data.SqlClient" connectionString="server=.;database=YourDB;User id= uidofDB;Password=pwd"/>
    </connectionStrings>
  Permalink  
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

check it
<configuration>
  <configsections>
    <sectiongroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <sectiongroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirepermission="false" allowdefinition="MachineToApplication" />
        <sectiongroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirepermission="false" allowdefinition="Everywhere" />
          <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirepermission="false" allowdefinition="MachineToApplication" />
          <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirepermission="false" allowdefinition="MachineToApplication" />
          <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirepermission="false" allowdefinition="MachineToApplication" />
        </sectiongroup>
      </sectiongroup>
    </sectiongroup>
  </configsections>
  <appsettings>
    <add key="con" value="Data Source=OMXHO11SFD0885\UMA;Initial Catalog=omx;Persist Security Info=True;User ID=sa;Password=pass" />
  </appsettings>
  <connectionstrings>
    <add name="cnn" connectionstring="Data Source=OMXHO11SFD0885\UMA;Initial Catalog=omx;Persist Security Info=True;User ID=sa;Password=pass" providername="System.Data.SqlClient" />
  </connectionstrings>
</configuration>
  Permalink  
Comments
muralikrishna53 3-Nov-11 7:59am
   
Getting one error!!

Only one <configsections> element allowed per config file and if present must be the first child of the root <configuration> element. C:\Documents and Settings\200228\My Documents\Visual Studio 2010\WebSites\registration\web.config
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

u can as:
<add connectionstring="server=.\SQLEXPRESS;database=DatabaseName;Trusted_connection=True;" name="strconnection" providername="System.Data.SqlClient" />
  Permalink  
Comments
muralikrishna53 3-Nov-11 7:58am
   
Getting one error!!

Only one <configsections> element allowed per config file and if present must be the first child of the root <configuration> element. C:\Documents and Settings\200228\My Documents\Visual Studio 2010\WebSites\registration\web.config

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.180111.1 | Last Updated 3 Nov 2011
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100