如何使用asp.net在web.config文件中写入连接字符串? [英] How to write connection string in web.config file using asp.net?

查看:77
本文介绍了如何使用asp.net在web.config文件中写入连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用asp.net在web.config文件中写入连接字符串,

我只是应用了这段代码:

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>



但出现一个错误!
元素"configSections"具有无效的子元素"add".可能的元素列表:"section,sectionGroup".



but getting one error!
"The element ''configSections'' has invalid child element ''add''. List of possible elements expected: ''section, sectionGroup''.

推荐答案

Place这样
您需要将其放置在configuration标签和configsections 标签之外

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>


检查它
<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>


u可以作为:
u can as:
<add connectionstring="server=.\SQLEXPRESS;database=DatabaseName;Trusted_connection=True;" name="strconnection" providername="System.Data.SqlClient" />


这篇关于如何使用asp.net在web.config文件中写入连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆