Sample script I used to create a linked server.
More explanation later...
EXEC master.dbo.sp_addlinkedserver @server = N'<linkedservername>', @provider=N'SQLNCLI', @datasrc=N'<sqlservername\ instance,port>', @srvproduct='<anything could be db name but it doesn't matter>';
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'<linkedservername>',@useself=N'True',@locallogin=NULL,@rmtuser=NULL,@rmtpassword=NULL;
EXEC master.dbo.sp_serveroption @server=N'<linkedservername>', @optname=N'collation compatible', @optvalue=N'false';
EXEC master.dbo.sp_serveroption @server=N'<linkedservername>', @optname=N'data access', @optvalue=N'true';
EXEC master.dbo.sp_serveroption @server=N'<linkedservername>', @optname=N'dist', @optvalue=N'false';
EXEC master.dbo.sp_serveroption @server=N'<linkedservername>', @optname=N'pub', @optvalue=N'false';
EXEC master.dbo.sp_serveroption @server=N'<linkedservername>', @optname=N'rpc', @optvalue=N'false';
EXEC master.dbo.sp_serveroption @server=N'<linkedservername>', @optname=N'rpc out', @optvalue=N'false';
EXEC master.dbo.sp_serveroption @server=N'<linkedservername>', @optname=N'sub', @optvalue=N'false';
EXEC master.dbo.sp_serveroption @server=N'<linkedservername>', @optname=N'connect timeout', @optvalue=N'0';
EXEC master.dbo.sp_serveroption @server=N'<linkedservername>', @optname=N'collation name', @optvalue=null;
EXEC master.dbo.sp_serveroption @server=N'<linkedservername>', @optname=N'lazy schema validation', @optvalue=N'false';
EXEC master.dbo.sp_serveroption @server=N'<linkedservername>', @optname=N'query timeout', @optvalue=N'0';
EXEC master.dbo.sp_serveroption @server=N'<linkedservername>', @optname=N'use remote collation', @optvalue=N'true';
EXEC master.dbo.sp_serveroption @server=N'<linkedservername>', @optname=N'remote proc transaction promotion', @optvalue=N'true';
------------------------------------
Script used to set up security options for one linked server:
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'<linkedservername>',@useself=N'False',@locallogin=NULL,@rmtuser=N'lawlex_user',@rmtpassword='<somepassword>'
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'<linkedservername>',@useself=N'True',@locallogin=N'lawlex_user',@rmtuser=NULL,@rmtpassword=NULL
GO
No comments:
Post a Comment