ASP.NET——設定檔

來源:互聯網
上載者:User

標籤:style   io   os   ar   strong   檔案   資料   sp   on   

 

一、連接字串

1、通過<connectionStrings>方式:

  • 方式一:SqlServer身分識別驗證

<connectionStrings>
  <add name="SZQ" connectionString="Server=.;Database=cwbaseSZQZ;User ID=LCSZQZ;Password=123456"              providerName="System.Data.SqlClient"/>
</connectionStrings>

   說明:Server=.;表示本機上的資料庫;Database=cwbaseSZQZ表示本機上的資料庫名字為cwbaseSZQZ;後面的為使用者名稱和密碼;providerName表示提供者。

  • 方式二:用windows驗證方式:

<connectionStrings>
  <add name="SZQ" connectionString="Server=.;AttachDbFilename=|DataDirectory|\\data.mdf;
    Integrated Security=true" providerName="System.Data.SqlClient" />
</connectionStrings>

  說明:AttachDbFilename=|DataDirectory|\\data.mdf表示資料庫的檔案路徑;其中|DataDirectory|表示方案總管中的特殊的檔案夾App_Data。“\”表示逸出字元,“\\”才表示真正的“\”;Integrated Security=true表示用windows驗證方式驗證。

  • 在程式碼中擷取<connectionStrings> 標籤裡的連接字串:

    引用命名空間:Using System.Configuration

string connStr = ConfigurationManager.ConnectionStrings["SZQ"].ConnectionString;

2.通過<appSettings>方式:

該方式實際上與上一個類似:

  • 方式一:SqlServer身分識別驗證

<appSettings>
  <add key="SZQ" value="Server=.;Database=cwbaseSZQZ;User ID=LCSZQZ;Password=123456" />
</appSettings>

  • 方式二:用windows驗證方式:

<appSettings>
  <add key="SZQ" value="Server=.;AttachDbFilename=|DataDirectory|\\data.mdf;
    Integrated Security=true" />
</appSettings>

  • 在程式碼中擷取<appSettings> 標籤裡的連接字串:

引用命名空間:Using System.Configuration ;  

string connStr =  ConfigurationManager.AppSettings["SZQ"].ToString();

 

 

ASP.NET——設定檔

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.