ado.net(1)

來源:互聯網
上載者:User

標籤:blog   io   使用   ar   資料   div   on   cti   log   

connection對象處於最頂層,是所有資料請求的關口

資料庫連接過程

SqlConnection theConnection = new SqlConnection();            //建立一個connection的對象執行個體            theConnection.ConnectionString = "server=.;integrated security=true;";            //設定其連接字串,本地串連,整合安全連線            //在連接字串作為參數傳給建立connection對象執行個體的代碼前,最好將其賦給一個字串            //string connectionstring = "server=.;integrated security=true;";            //SqlConnection theconnection=new SqlConnection(connectionstring);            //在連接字串作為參數傳給建立connection"            theConnection.Open();            if (theConnection.State == System.Data.ConnectionState.Open)                Console.WriteLine("database connection is open");

  sqlclient資料提供了另一種構造連接字串的方法,即使用sqlconnectionstringbuilder對象

使用SqlConnectionStringBuilder的好處是,在輸入無效的連接字串時引發異常

三種方法來指定串連資料來源的屬性

1通過connection對象的connectionString屬性指定連接字串

2將連接字串傳入connection對象的建構函式中

3使用資料來源設定精靈

ado.net(1)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.