SQL Server inserts data across databases

Source: Internet
Author: User

Create a connection to the server that can exist on the server after it is created and can be reused in different locations, similar to system functions

execsp_addlinkedserver'RemoteServer','','SQLOLEDB','192.168.3.225' execsp_addlinkedsrvlogin'RemoteServer','false',NULL,'SA',' [email protected]' 

Delete Connection

exec ' RemoteServer ' ' droplogins '

How to use: (Connect. database. dbo. Table)

Select Top  - *  from  RemoteServer.Suncome.dbo.AkEL

The following is called through a trigger

Create TriggerSyncbarcode onBarcodecompinfoafterUpdate,Insert asDeclare @Barcode nvarchar( -)Select @Barcode=Barcode frominsertedDeclare @num int--used to determine if the above number is present in the Bdvendor table to infer whether to add or modifySelect @num=COUNT(*) fromRemoteServer.Suncome.dbo.AkBarcodeCompInfowhereBarcode=@Barcodeif @num=0begin  Insert  intoRemoteServer.Suncome.dbo.AkBarcodeCompInfo (Barcode,ordernumber,printdate,linecode)Select [Barcode],[Workorderid],[PrintDate],[BC]  frominsertedEnd

But there's no egg to use.

Right-click on "My Computer"--"manage"--"services and Applications"--"services"---start the "Distributed Transaction Coordinator" service, open the remote server and the local server 135 port after starting the distributed service. Because the remote distributed service requires this port to communicate.
1: Open "Control Panel"--"Administrative Tools"--"Component Services"
2: Right-click "My Computer" under "Computer"--"Properties"--select "MSDTC" tab
3: Click the "Security Configuration" button,
4: Network DTC Access is checked on, allow remote clients, allow remote administration, allow inbound,
Allow outbound, do not ask for authentication check on.
Note: The above steps require two servers to be configured.

SQL Server inserts data across databases

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.