将标签与web.config一起使用 [英] Using the tag with web.config

查看:114
本文介绍了将标签与web.config一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在该web.config中增强一个项目

Hello All,

I am enhancing a project, in that web.config

<connectionstrings>
              <remove name="LocalSqlServer" />
    </connectionstrings>



我需要在必须指定的地方指定数据库名称吗?

请帮我.

问候
Praveen



I need to specify the database name where I have to specify?

Please hep me.

Regards
Praveen

推荐答案

您可以这样定义
You can define like this
<connectionStrings>    
    <add name="connstr"  providerName="System.Data.SqlClient" connectionString="Data Source=Servername;Initial Catalog=DBName;Integrated Security=True"/>
  </connectionStrings>

Accessing in C#:
string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ToString();

Or
<appSettings>
        <add key="constr" value="Data Source=ServerName;Initial Catalog=DBName;User ID=sa;Password=123456"/>    
  </appSettings>

Accessing in C#:

string connStr = System.Configuration.ConfigurationManager.AppSettings["constr"].ToString();




appSettings用于可存储的任何数据字符串,而connectionString仅用于存储数据库连接字符串.




appSettings is meant for any data string that can be stored while connectionString is meant for storing the database connection strings only.


这篇关于将标签与web.config一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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