Click here to Skip to main content
15,885,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to write connection string in web.config file using asp.net,

i just applied this code:

HTML
<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
Updated 2-Nov-11 19:03pm
v4

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

XML
<connectionStrings>
        <add name="ConnectionString" providerName="System.Data.SqlClient" connectionString="server=.;database=YourDB;User id= uidofDB;Password=pwd"/>
    </connectionStrings>
 
Share this answer
 
v3
check it
C#
<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>
 
Share this answer
 
Comments
[no name] 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
u can as:
HTML
<add connectionstring="server=.\SQLEXPRESS;database=DatabaseName;Trusted_connection=True;" name="strconnection" providername="System.Data.SqlClient" />
 
Share this answer
 
Comments
[no name] 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900