C#中怎么新建DButility数据库帮助类库
1、在解决方案中新建一个DBUtility类库,作为访问MySQL的通用sql语句存放>所在/p>
2、引入MySql.Data.dll
3、配置web.configMySQL数据库连接字符串
在解决方案根目录下打开web.config配置文件,在connectionStrings节点中加入MySQL连接字符串

<connectionStrings>
<addname="DBConnectionString"connectionString="DataSource=127.0.0.1;Database=你的数据库名;UserID=用户名;Password=密码"providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
web.config配置文件的访问度高吗
web.config配置文件的访问度取决于应用程序的需求和配置信息的复杂程度。通常情况下,web.config配置文件的访问度较高,因为它包含了应用程序的重要配置信息,如数据库连接字符串、安全设置、日志记录等。这些配置信息的改变可能需要频繁访问和修改web.config文件。
同时,web.config文件也是开发人员和系统管理员进行应用程序维护和调试的重要资源,因此其访问度较高。
ASP.NETMVC4中如何读取web.config中的>设置/h2>
用ConfigurationManager这个类。
ASP.NET MVC 4中读取web.config中的配置方法如下:
1、web.config内容:<?xml version="1.0" encoding="utf-8" ?><configuration><system.web><compilation defaultLanguage="c#" debug="true" /></system.web><appSettings><add key="ConnectionInfo" value="server=(local);database=Northwind;Integrated Security=SSPI" /></appSettings></configuration>
2、读取配置的方法:void Page_Load(object sender, EventArgs e){string connectionInfo = ConfigurationSettings.AppSettings["ConnectionInfo"];using(SqlConnection connection = new SqlConnection(connectionInfo)){connection.Open();// perform work with connection} }