See what user you are connecting to linked SQL server
I wanted to share with you guys a really handy little SQL query that is extremely useful if you are troubleshooting SQL Server linked server connectivity. ย You may have setup a local server login to remote server login mapping which translates your Windows login to a remote user. ย Or, you may have a user defined in the “for a login not defined in the list above” section of the Linked Server Properties. ย How do you know if your user mappings are working? ย Let’s use a query to see what user you are connecting to linked SQL server with.
See what user you are connecting to linked SQL server
As mentioned above, your linked server properties may look similar to the screen below. ย Here there is an entry in the top section for local server login to remote server login mapping. ย So if we are logged in as the “Local Login” for instance, TESTDOMAINjdoe then we can set the remote user to be SA or another SQL login. ย The way the linked server properties work is if the top section is either blank or doesn’t match, then it goes to the next section which then processes how things are going to be authenticated. ย As you can see below, the radio button “Be made using this security context” is selected. ย This means that we are hard setting a SQL login as a catchall for all other logins passed over to the linked server.
SQL Query to find logins
The following SQL query will show theย localย userย as well as theย remoteย user being invoked.
select suser_sname() as LocalUsr, @@servername as LocalSrv,* from openquery(sqlserver,'select suser_sname(), @@servername')
Replace theย sqlserver string above with your actual SQL server name. ย Results will look similar to the following:
Final Thoughts
Hopefully if you have been frustrated in the past on being able to see what user you are connecting to linked SQL server, this post will help with that. ย Look for an upcoming post on general troubleshooting steps in troubleshooting MSDTC connections in general.