2008年8月15日 星期五

SQL SERVER 2005 如何開啟異動遠端連結伺服器的資料

To allow the network transaction, you must enable MSDTC. To do this, follow these steps:
a. Click Start, and then click Run.
b. In the Run dialog box, type dcomcnfg.exe, and then click OK.
c. In the Component Services window, expand Component Services, expand Computers, and then expand My Computer.
d. Right-click My Computer, and then click Properties.
e. In the My Computer Properties dialog box, click Security Configuration on the MSDTC tab.
f. In the Security Configuration dialog box, click to select the Network DTC Access check box.
g. To allow the distributed transaction to run on this computer from a remote computer, click to select the Allow Inbound check box.
h. To allow the distributed transaction to run on a remote computer from this computer, click to select the Allow Outbound check box.
i. Under the Transaction Manager Communication group, click to select the No Authentication Required option.
j. In the Security Configuration dialog box, click OK.
k. In the My Computer Properties dialog box, click OK.

SQL SERVER trigger 中的 SQL 語法範例

update

update a set c1=i.c1 from inserted i,table1 a where i.id=a.id;

insert

insert into table1 (c1) select c1 from inserted;


inserted 代表新增或更新的資料列表格

2008年8月4日 星期一

善用 StringBuilder 類別

通常許多人處理字串串連時,都會用 + 這個運算子來處理
但是這雖然也是可以正常處理字串相加,不過對系統效能上卻造成極大的負擔
這是因為使用 string 這個類別時會配置一段記憶體來儲存字串
而當以 + 運算子處理字串相加時或字串資料變更時
系統必須配置一段新的記憶體來儲存新字串的動作 (如兩字串相加後的新字串)
再反配置舊的記憶體
每次配置記憶體和反配置都會造成 CLR 的工作
當然這些動作都是在幕後處理完成,每次處理的時間非常的短
但是如果大量處理這些字串運算或大塊記憶體時,累加起來的時間就不只是如此了
尤其是在 Web 伺服器上執行的 ASP.Net 應用程式來說更是會造成嚴重的影響

而 StringBuilder 物件則不同,它會保留自己的字串緩衝區
所有的動作都在同一塊記憶體工作,減少記憶體配置的動作
除非緩衝區大小不夠處理時,才會作記憶體重新配置
自然能有效提升效能

原文出處

Entity Framework 建立新物件並儲存後馬上取得關聯資料

使用 CreateProxy 建立物件,不要直接 new var newmodel = _contextXXX.CreateProxy<yyy>(); ... _contextXXX.yyy.Add(newmodel); await _contextXXX.SaveC...