SQL Server: How to create a linked server

I was trying to import data from a table of production SQL server to my local SQL server with below query. I wanted to deploy this in one of my SP. I encountered with an error.
SELECT * INTO LocalTable FROM [192.168.0.111].ProdDatabase.dbo.ProdTestTable


Msg 7202, Level 11, State 2, Line 3
Could not find server '192.168.0.111' in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers.
Solution:
As we are trying to get the data from another server, an authentication is required. A link table has to be created in local SQL Server to access data from another server.



Enter remote Server IP.


Click on Security available at left pane. Enter your local and remote SQL Server credentials as in below screenshot.
Note: You can provide your local system name when your SQL Server login is Windows authentication.


If you are calling stored procedure in remote server from local SQL server or vice-versa, set RPC and RPCOut options to True whcih are available under Server Options.



No comments:

Post a Comment