連線資料庫字串

2022-03-26 13:55:44 字數 839 閱讀 8596

system.data.sqlclient 命名空間下有個類: sqlconnectionstringbuilder  ,可以幫助我們維護鏈結字串。 這個類對我們下面的需求場景很有幫助。

persist security info=false;integrated security=true;initial catalog=northwind;server=(local);

persist security info=false;integrated security=true;initial catalog=northwind;server=(local);connect timeout=0;

注: 在沒有設定 connect timeout 時, connect timeout 預設為15秒,如果 connect timeout 設定為0,則表示永遠不超時。這個設定是以秒為單位的。

其實我們完全可以只配置乙個資料庫鏈結字串,然後使用 sqlconnectionstringbuilder 類來幫助我們實現不同 connect timeout 的需求。

演示**如下:

// connstring 原汁原味的配置的鏈結字串

sqlconnectionstringbuilder connstr = new sqlconnectionstringbuilder(connstring);

// 不論之前是否設定了connect timeout,這裡都強制設定為用不超時

connstr.connecttimeout = 0;

// 使用新組合後的鏈結字串

sqlconnection conn = new sqlconnection(connstr.connectionstring);

在ASP中連線資料庫(連線字串)

在asp中連線資料庫 一 訪問資料庫的原理 在asp中,用來訪問資料庫的物件統稱ado物件 active data objects 主要含有三種物件 connection recordset和 mand,其中connection負責開啟或連線資料庫,recordset負責訪問資料表,mand負責對資...

資料庫連線字串 EXCEL 連線字串

odbc 標準driver driverid 790 dbq c myexcel.xls defaultdir c mypath sql表示式 select from sheet1 例如 在excel工作表名稱後面跟 字元並且使用 將其括起來。ole db 標準provider microsoft....

資料庫連線字串 Oracle 連線字串

odbc 新版本driver server myserveraddress uid myusername pwd mypassword 舊版本driver connectstring oracleserver.world uid myusername pwd mypassword ole db,ol...