Is there any way to change the properties (Product name, data source, provider string, etc...) of an existing linked server? When I go to the properties screen, all the options are grayed out.
9 Answers
Here's the command.
EXEC master.dbo.sp_serveroption @server=N'<SERVERNAME>', @optname=N'name', @optvalue=N'<NEWNAME>'
Replace 'SERVERNAME' with the current name of the linked server. Replace 'NEWNAME' with the new name you want to give the linked server.
3 Comments
In SQL Server management Studio click right on the linked server, choose "Script Linked Server as' then choose 'DROP and CREATE to' and then "New Query Editor Window'. You can now adjust any settings that you want to adjust in the script and then run it. The existing linked server will be dropped and a new one created.
1 Comment
The only option you have is to use sp_setnetname. You can use it to change the data_source of the linked server (destination), e.g.:
DECLARE @name sysname = 'SRVRNAME', @datasource sysname = 'srvr.name.com';
EXECUTE sp_setnetname @server = @name, @netname = @datasource;
2 Comments
I ended up creating a new linked server and deleting the old one. Unfortunately, there is no way to edit an existing instance
1 Comment
Merge of various responses, as well as reading documentation - this is only documented to work for SQL linked servers, not alternate data sources:
select server_id, name, data_source from sys.servers where product = 'SQL Server'
DECLARE @oldName nvarchar(30) = 'oldSERVER', --must match current entry under sys.servers.name
@name sysname = 'newServer',
@datasource sysname = 'newServer.DNSDomainName.com' -- can be a windows FDQN that is not SQL valid if needed for RPC cross domain resolution
/* Comment out this marker to perform update
EXEC master.dbo.sp_serveroption @server=@oldName, @optname=N'name', @optvalue=@name
EXECUTE sp_setnetname @server = @name, @netname = @datasource;
select server_id, name, data_source from sys.servers where product = 'SQL Server'
--*/
2 Comments
Check out sp_serveroption. This is how the GUI would ultimately do it anyways. If changing what you were trying to change is ultimately not allowed, you should get a meaningful error message from this stored procedure.
Comments
My experience (I'm using SQL Server 2016 to link to a SQL Server 2012 instance, and I wanted to rename the linked server and change it's target) was that I needed to combine the answers from Xipooo and Jordan Parker.
sp_serveroption renamed the linked server, and sp_setnetname changed the target of the linked server.