對于ADO.NET代碼編制與列表學(xué)習(xí)
首先對于ADO.NET代碼要先保存起來,當(dāng)下一次需要打開連接地時(shí)候就將先前地Connection 交給下一個(gè)連接。這就是ADO.NET代碼的編制,制定ADO.NET代碼的相關(guān)技巧。。
如果您地項(xiàng)目是ASP.NET/WebService 我們會建議您運(yùn)用ADO.NET代碼因?yàn)檫@個(gè)功能可以幫助您減少由于頻繁創(chuàng)建連接帶來地巨大系統(tǒng)開銷。
如果您地系統(tǒng)是一個(gè)C/S模型結(jié)構(gòu),我們會不建議您運(yùn)用ADO.NET代碼,這是由于一般而言,在C/S這樣地模型中,每一個(gè)用戶均為運(yùn)用自己地用戶名密碼去連接后臺數(shù)據(jù)庫,運(yùn)用地均為不同地Connection String,根本不會出現(xiàn)頻繁出現(xiàn)打開/關(guān)閉數(shù)據(jù)庫連接地問題。#t#
實(shí)際上在ADO.NET代碼模型中,您可以一直使一個(gè)Connection維護(hù)open地關(guān)閉,而不Close,這樣更可以提高您系統(tǒng)地性能,不會由于Connection Pool地額外檢查而帶來系統(tǒng)資源地消耗,相應(yīng)情況下也不必?fù)?dān)心一直打開地Connection長時(shí)間地占用了連接,導(dǎo)致其他地連接無法從ADO.NET代碼及時(shí)獲取到。(因?yàn)槟揪筒恍枰\(yùn)用到connection pool)
另外地一點(diǎn)備住:
- Enlist (True)
- When true, the pooler automatically enlists the connection in the current transaction context of the creation thread if a transaction context exists.
- Max Pool Size (100)
- The maximum number of connections allowed in the pool.
- Min Pool Size (0)
- The minimum number of connections maintained in the pool.
- ConnectionReset (True)
- Gets or sets a Boolean value that indicates whether the connection is reset when drawn from the connection pool.
- The value of the ConnectionReset property or true if no value has been supplied.
- This property corresponds to the "Connection Reset" key within the connection string.