求助!希望大家帮我解决几个问题!新手!
1、请问怎么从web.config中读出数据库的相关数据并连接数据库和执行数据库的相关操作?
有一个web.config的示例代码(密码没有直接写上,而是加密过的。要读取后在解密,然后连接数据库):
<?xml version="1.0" encoding="utf-8" ?><configuration> <configSections> <section name="AppSettings" type="System.Web.Configuration.NameValueSectionHandler" /> </configSections> <appSettings> <add key="jsfskg" value="" /> <add key="MyConn" value="Data Source=abcd;pooling=true;min pool size=10;max pool size=300;User Id=12345;Password=" /> <add key="MyPwd" value="Z%ML]V0692>A,"/> <!--value="fosf?0[J+t"/>--> <add key="HTTP_HOST" value="http://localhost" /> <add key="APPL_PHYSICAL_PATH" value="f:\webserver\123\" /> <add key="HTTP1" value="http://127.0.0.1" /> <add key="HTTP2" value="http://127.0.0.1" /> <add key="HTP" value="2" /> <add key="AjaxSrc" value="/ajax/common.ashx" /> <add key="AjaxSrc1" value="/ajax/zjdx.AjaxForm,zjdx.ashx" /> <add key="cjlrurl" value="http://127.0.0.1/XkLuenceWeb/XkService.asmx?wsdl"/> <add key="glkg" value="1"/> <add key="glgbym" value=""/> </appSettings> <system.web> <httpHandlers> <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" /> </httpHandlers> <compilation defaultLanguage="vb" debug="true" /> <customErrors mode="RemoteOnly" defaultRedirect="123.htm" /> <httpRuntime executionTimeout="1200" maxRequestLength="40960" /> <authentication mode="Windows" /> <authorization> <allow users="*" /> <!-- Allow all users value="Data Source=12345;User Id=12345;Password=12345"--> </authorization><sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="180" /> <globalization requestEncoding="GB2312" responseEncoding="GB2312" /> </system.web></configuration>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="default2.aspx.vb" Inherits="zjdx.default2" enableViewState="False" %>