June 25, 2013 at 9:54 am
Hi,
I have been asked to setup a script to make setting up mirroring a little quicker. The main problem is one must run the ALTER commands and create endpoint command on two different servers. Can this be done within the script with something like Connect to:: or linked servers, or something I don't know about?
CREATE ENDPOINT EndPointName
STATE=STARTED AS TCP(LISTENER_PORT = PortNumber, LISTENER_IP = ALL)
FOR DATA_MIRRORING(ROLE = PARTNER, AUTHENTICATION = WINDOWS NEGOTIATE, ENCRYPTION = REQUIRED ALGORITHM RC4)
-- On Mirror
-- How can I connect?
CREATE ENDPOINT EndPointName
STATE=STARTED AS TCP(LISTENER_PORT = PortNumber, LISTENER_IP = ALL)
FOR DATA_MIRRORING(ROLE = PARTNER, AUTHENTICATION = WINDOWS NEGOTIATE, ENCRYPTION = REQUIRED ALGORITHM RC4)
/*Set partner and setup job on mirror server*/
ALTER DATABASE DatabaseName SET PARTNER = N'TCP://PrincipalServer:PortNumber'
EXEC sys.sp_dbmmonitoraddmonitoring -- default is 1 minute
June 25, 2013 at 11:37 am
For Linked servers, i know you can do DDL commands, like CREATE TABLE, via EXECUTE AT;
I'd bet any other commands like the ALTER and CREATE ENDPOINT would work just as well ,
EXECUTE ( 'CREATE TABLE AdventureWorks2008R2.dbo.SalesTbl
(SalesID int, SalesName varchar(10)) ; ' ) AT SeattleSales;
Lowell
June 25, 2013 at 12:20 pm
Yes but those DDL commands often specify a from clause which is where I can put in the linked server. These do not.
June 25, 2013 at 12:25 pm
lmacdonald (6/25/2013)
Yes but those DDL commands often specify a from clause which is where I can put in the linked server. These do not.
ahh, you missed the point.
I created a linked server named SeattleSales.
the EXECUTE('some command') AT SeattleSales performs the action on the remote linked server, and not locally; you only need a four-part name for DML commands; for DDL, you use the AT <MyLinkedServer> format.
Lowell
June 25, 2013 at 12:34 pm
Oh nice, that may just work )
However my linked server is actually on the same machine, but another instance. There is a syntax error, it does not like the \ between servername\instance so I tried it like servername.instance and it did not like the slash or the period.
June 25, 2013 at 12:39 pm
lmacdonald (6/25/2013)
Oh nice, that may just work )However my linked server is actually on the same machine, but another instance. There is a syntax error, it does not like the \ between servername\instance so I tried it like servername.instance and it did not like the slash or the period.
oh that's easy to fix too; you just need to put it in brackets:
EXECUTE AT('some command') AT [macdonald\SQL2008]
Lowell
June 25, 2013 at 1:44 pm
Thanks, that helped so much!
June 26, 2013 at 8:21 am
To bad variables get lost when you do an execute at another server. I thought everything was good but now I have that problem.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply