<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      web應用程序中的數據庫連接(1)

      [摘要]web.config文件是標準的xml文件,我們可以使用它來為一臺機器下的每一個web應用程序或某個應用程序或一個目錄下的asp.net頁面來進行設置,當然,它也可以為一個單獨的web頁面進行設置。 如:網站的主目錄是\inetpub\wwwroot\,那么我們將web.config放置于其下,...
        web.config文件是標準的xml文件,我們可以使用它來為一臺機器下的每一個web應用程序或某個應用程序或一個目錄下的asp.net頁面來進行設置,當然,它也可以為一個單獨的web頁面進行設置。 

      如:網站的主目錄是\inetpub\wwwroot\,那么我們將web.config放置于其下,那么這個網站中的應用程序將被web.config中的設置所影響。 
      e.g.: 
      <?xml version="1.0" encoding="gb2312" ?> 
      <configuration> 
       <system.web> 
        <compilation defaultlanguage="vb" debug="true" /> 
        <customerrors mode="remoteonly" defaultredirect="js/error.htm"> 
         <error statuscode="404" redirect="js/filenotfound.aspx" /> 
         <error statuscode="500" redirect="js/error.htm" /> 
        </customerrors> 
        <authentication mode="windows" /> 
        <authorization> 
         <allow users="*" /> 
        </authorization> 
        <httpruntime maxrequestlength="4000" usefullyqualifiedredirecturl="true" executiontimeout="45" /> 
        <trace enabled="false" requestlimit="10" pageoutput="false" tracemode="sortbytime" localonly="true" /> 
        <sessionstate mode="inproc" stateconnectionstring="tcpip=127.0.0.1:43444" cookieless="false" timeout="20" /> 
        <globalization requestencoding="gb2312" responseencoding="gb2312" fileencoding="gb2312" /> 
       </system.web> 
       <appsettings> 
        <add key="connstring" value="uid=flash;password=3.1415926;database=news;server=(local)" /> 
       </appsettings> 
      </configuration> 

      這里我們討論一下如何在web.config中設置數據庫連接。 

      1、連接一個數據庫: 
      在web.config中的<configuration>后加入 

      <appsettings> 
          <add key="connstring"  
          value="uid=flash;password=3.1415926;database=news;server=(local)" /> 
      </appsettings> 

      在程序中,你可以使用以下代碼來使用web.config中的設置: 

      -----vb.net----- 
      imports system.configuration 
      dim myvar as string  
       myvar=configurationsettings.appsettings("connstring") 
      -----c#----- 
      using system.configuration; 
      string myvar; 
      myvar=configurationsettings.appsettings["connstring"]; 

      2、連接多個數據庫 
      同理,那就是使用多個不同的key值來設置 





      日韩精品一区二区三区高清