在应用程序设置和连接字符串中写入连接字符串有什么区别

在应用程序设置和连接字符串中写入连接字符串有什么区别

问题描述:

在应用程序设置和连接字符串中写入连接字符串有什么区别?

what is the difference writing connection string in app setting and connectionstring?

您将以不同的方式访问它们.您可以使用ConfigurationManager.AppSettings ["connectionStringName"]或做ConfigurationManager.ConnectionStrings ["connectionStringName"]

将连接字符串放在ConnectionStrings部分中是有意义的.另外,Visual Studio中的某些数据驱动向导会在其中查找现有的连接字符串.
You will access them differently. You can use ConfigurationManager.AppSettings["connectionStringName"] or you can do ConfigurationManager.ConnectionStrings["connectionStringName"]

It would make sense to put a connection string in the ConnectionStrings section. Also, some of the data driven wizards in Visual Studio will look there for existing connection strings.


从我的角度来看,以下是不同之处:

1.如果连接字符串位于
From my perspective following are differences:

1. If connection string is in
<connectionstring></connectionstring>

,它允许您从IIS->中配置它们.应用程序属性->连接字符串选项卡.与appsettings隔离.

2.如果使用的是任何框架,则它将始终从

, it allows you to configure these from IIS-> Application properties -> Connection string tab. Isolates from appsettings.

2. If you are using any framework, then it would always read the connection string from

<connectionstring></connectionstring>

.

3.新标签允许您仅加密连接字符串,否则最终将导致整个应用程序设置被加密,修改应用程序设置将变得棘手.

IMO始终使用

.

3. New tag allows you to encrypt just the connection string otherwise you will end up with whole appsettings encrypted and modifying appsettings would become tricky.

IMO always use

<connectionstring></connectionstring>

存储连接字符串.

-Rohit

to store connection string.

-Rohit