SQL Server DT問與答
2024-08-31 00:48:00
供稿:網友
 
q: 假設我現在有2臺sql server (windows server 2003 + sql server 200 sp3),分別叫db01和db02,互相信任,互相把對方加入了linked servers的列表,常規訪問無任何問題,但是無法啟用分布式事務,例子如下:
在db01上運行下列sql命令:
begin tran
select top 1 * from item
select top 1 * from db02.production.dbo.item
rollback tran
在第2個select語句處提示the operation could not be performed because the ole db provider 'sqloledb' was unable to begin a distributed transaction.
[ole/db provider returned message: new transaction cannot enlist in the specified transaction coordinator. ]
ole db error trace [ole/db provider 'sqloledb' itransactionjoin::jointransaction returned 0x8004d00a].
把begin tran換成begin distributed transaction,結果相同。
在這2臺服務器上,已經同時啟用了ms dtc服務,并在component service中設定了ms dtc各種安全支持選項全開(步驟如下:
1. click start, point to all programs, point to administrative tools, and click component services. 
2. in the component services console, expand component services, expand computers, right-click my computer, and then click properties. 
3. in the my computer properties dialog box, on the msdtc tab, click security configuration. 
4. in the security configuration dialog box, select the network dtc access check box, select the network administration check box, select the network transactions check box, select the network clients check box, select the transaction internet protocol (tip) transaction check box, and then click ok. 
5. restart the computer. 
)。
因為服務器正在運行任務,所以我沒有重新啟動(僅僅重新啟動了dtc服務).
是什么原因導致無法啟動事務呢? 
a:
一. (缺) 
二.兩臺機的msdtc是否都打開了.
三.msdtc設置是否正確. 
1.打開命令提示,運行"net stop msdtc",然后運行"net start msdtc"。 
2.轉至"組件服務管理工具"。 
3.瀏覽至"啟動管理工具"。 
4.選擇"組件服務"。 
 a.展開"組件服務"樹,然后展開"我的電腦"。 
 b.右鍵單擊"我的電腦",然后選擇"屬性"。 
 c.在 msdtc 選項卡中,確保選中了下列選項: 網絡 dtc 訪問 
 網絡管理 
 網絡事務 
    xa 事務 
 e.另外,"dtc 登錄帳戶"一定要設置為"nt authority/networkservice"。 
5.單擊"確定"。這樣將會提示您"ms dtc 將會停止并重新啟動。 
  所有的依賴服務將被停止。請按'是'繼續"。單擊"是"繼續。 
6.單擊"確定"關閉"我的電腦"屬性窗口。 
四. 
msdtc依賴于rpc,rpc使用的端口是135,測試135端口是否打開.是否有防火墻?如果有先關了防火墻. 
telnet ip 135 
如果是關閉的打開它. 
五. 
有的機由于各種原因),sqloledb不能使用分布式事務,更改為"msdasql" 的odbc方式聯接. 
使用rras而不是ras.(控制面版--管理工具--遠程服務管理器) 
check whether you are using remote access server (ras) to access remote servers. if so, make sure that you have implemented routing ras (rras). linked server does not work on ras because ras allows only one way communication. 
七.檢查你的兩臺服務器是否在同一個域中. 
如果不在同一個域中,是否建立可信任聯接. 
八.如果是win2000,升級到sp4
九.升級mdac到2.6以上,最好是2.8.
十.要安裝sql的最新補丁: sp3a 
'全部補丁的位置 
http://www.microsoft.com/downloads/details.aspx?displaylang=zh-cn&familyid=9032f608-160a-4537-a2b6-4cb265b80766 
'應該安裝的補丁sql 2000 sp3 
http://download.microsoft.com/download/d/d/e/dde427eb-0296-4eac-a47c-d11a66b03816/chs_sql2ksp3.exe 
本人認為: 
1、環境是重要的。
2、工具是很重要的。 
(1)懷疑是135端口,就用一個檢查端口的工具去看,發覺端口沒有問題。 
(2)下了http://download.microsoft.com/download/complus/msdtc/1.7/nt45/en-us/dtcping.exe 
工具,測試,看了readme,說由三步,第一步驗證名稱,第二步驗證rpc,第三步dtc,好,我居然發現名字驗證都沒通過, 
總于發現tcp/ip的netbios被關掉了,咳 dtc 居然一定要名稱。不用ip. i 服了 he了。 
3、出現遠地的計算機只能用ip地址訪問不能進行名字訪問,我碰到如下。 
     (1)、路由的設置的問題,倆個路由是否確定無誤(vpn能連通并不代表名字訪問能成功,版本一致,允許芳臨訪問,無其他異常)。 
     (2)、是否出現錯誤日志dcom,出現此錯誤也將不能進行名字訪問。 
     (3)、相應tcp/ip的netbios是否打開。