I am trying to verify a proof of concept that I can run a distributed transaction on two linked SQL servers linked using sp_addlinkedserver - their names are Server1 and Server2, both of which are executed by default. Each server contains one database, the source and destination, respectively, and the destination database contains a separate table called "Output", i.e.
Server1.Source Server2.Destination.Output
The OUTPUT table has the following structure:
OUT_PKEY int identity(1,1) primary key, OUT_TEXT nvarchar(255)
From Server1, I called sp_addlinkedserver 'Server2' to link the two databases, and I tried to run the following query to check if this link really works:
Select * From Server2.Destination.dbo.Output
The following exception was returned to me:
Access to the remote server is denied because there is no name mapping.
Fairly enough, so from Server1 I run sp_addlinkedsrvlogin 'Server2', which according to the documentation says that it should accept the credentials of the user who is executing the request remotely (i.e. from server 1) and apply these credentials to Server2. This means that since I am connected to Server1 using Windows authentication, this should mean that my Windows credentials also apply to Server2.
Now the error message changes to:
Login failed for user "NT AUTHORITY \ ANONYMOUS LOGON".
Having Googled this exception, I came up with nothing useful that pointed me in the right direction. What am I missing? I would expect that [if the login fails] the exception will refer to my Windows credentials, and not to anonymous login credentials.
It seems that as soon as I get the work of the link itself, the distributed transactions themselves should be pretty simple - the documentation implies that I just need to make sure that the DTC service is running on Server1, and that any requests made on Server1 will be broadcast by reference :
- Turn SET XACT_ABORT ON until my distributed transaction is initialized
- I am using BEGIN DISTRIBUTED TRANSACTION instead of BEGIN TRANSACTION
- If I want to reference a non-standard instance of SQL Server on Server 2000, I replace any instances of Server2 in my query with [Server2 \ InstanceName]
My questions are as follows:
- How do I get through this problem? The stored procedure sp_addlinkedsrvlogin itself does not seem to do this trick.
- Is it really as simple as starting a distributed transaction, as the documentation suggests?
TIA