2552-08-25

เรามาทำ transaction ข้าม server กัน

To work around this problem, follow these steps on the computer that Windows Server 2003 or Windows XP SP2 is installed on:
Make sure that the Log On As account for the MSDTC service is the Network Service account. To do this, follow these steps:
Click Start, and then click Run.
In the Run dialog box, type Services.msc, and then click OK.
In the Services window, locate the Distributed Transaction Coordinator service under Name in the right pane.
Under the Log On As column, see whether the Log On As account is Network Service or Local System.

If the Log On As account is Network Service, go to step 2. If the Log On As account is Local System account, continue with these steps.
Click Start, and then click Run.
In the Run dialog box, type cmd, and then click OK.
At the command prompt, type Net stop msdtc to stop the MSDTC service.
At the command prompt, type Msdtc –uninstall to remove MSDTC.
At the command prompt, type regedit to open Registry Editor.
In Registry Editor, locate the following key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSDTCregistry key.

Delete this key.
Quit Registry Editor.
At the command prompt, type Msdtc –install to install MSDTC.
At the command prompt, type Net start msdtc to start the MSDTC service.

Note that the Log On As account for the MSDTC service is set to Network Service account.
Enable MSDTC to allow the network transaction. To do this, follow these steps:
Click Start, and then click Run.
In the Run dialog box, type dcomcnfg.exe, and then click OK.
In the Component Services window, expand Component Services, expand Computers, and then expand My Computer.
Right-click My Computer, and then click Properties.
In the My Computer Properties dialog box, click Security Configuration on the MSDTC tab.
In the Security Configuration dialog box, click to select the Network DTC Access check box.
To allow the distributed transaction to run on this computer from a remote computer, click to select the Allow Inbound check box.
To allow the distributed transaction to run on a remote computer from this computer, click to select the Allow Outbound check box.
Under the Transaction Manager Communication group, click to select the No Authentication Required option. Set No Authentication Required on both the client and the remote systems.
In the Security Configuration dialog box, click OK.
In the My Computer Properties dialog box, click OK.
Configure Windows Firewall to include the MSDTC program and to include port 135 as an exception. To do this, follow these steps:
Click Start, and then click Run.
In the Run dialog box, type Firewall.cpl, and then click OK
In Control Panel, double-click Windows Firewall.
In the Windows Firewall dialog box, click Add Program on the Exceptions tab.
In the Add a Program dialog box, click the Browse button, and then locate the Msdtc.exe file. By default, the file is stored in the :\Windows\System32 folder.
In the Add a Program dialog box, click OK.
In the Windows Firewall dialog box, click to select the msdtc option in the Programs and Services list.
Click Add Port on the Exceptions tab.
In the Add a Port dialog box, type 135 in the Port number text box, and then click to select the TCP option.
In the Add a Port dialog box, type a name for the exception in the Name text box, and then click OK.
In the Windows Firewall dialog box, select the name that you used for the exception in step j in the Programs and Services list, and then click OK.
Test pinging from the host server to the remote server, and from the remote server to the host server, using the netbios name (server name, without the domain). Microsoft Distributed Transaction Coordinator uses the netbios name, not the fully qualified domain name, to locate servers. If name resolution fails, distributed transactions will fail. If pings using the netbios name fails, refer to the following knowledge base article:


set เสร็จแล้วมาดูตัวอย่าง sql กัน

SET xact_abort ON
begin DISTRIBUTED tran

exec dbo.InsertToSp
commit

---------------------------------------------
Store ที่เราต้องการทำการ execute

BEGIN

begin transaction
insert into [SAPEREDB].LAC.dbo.SysCompany (CompanyID,CompanyName)values('00002','Intelsys')

-- Error Checking
IF @@ERROR <> 0
BEGIN
-- process failure.
ROLLBACK;
RETURN @@ERROR;
END
ELSE
BEGIN
-- Process success.
COMMIT;
RETURN @@ERROR;
END;
END

credit:http://support.microsoft.com/kb/839279

ไม่มีความคิดเห็น:

แสดงความคิดเห็น