SQL server, linked server error with open query -
i can't figure out why getting error on open query line:
"could not find server 'server_name' in sys.servers. verify correct server name specified. if necessary, execute stored procedure sp_addlinkedserver add server sys.servers."
when run code in parts works...
if not exists(select * sys.servers name = server_name) begin exec sys.sp_addlinkedserver @server = server_name, @srvproduct = 'sql server' exec sys.sp_addlinkedsrvlogin server_name, 'false', null, 'username', 'password' end select * openquery(server_name, 'select * table') if exists(select * sys.servers name = server_name) exec sys.sp_dropserver @server = server_name, @droplogins = 'droplogins'
Comments
Post a Comment