Hi All,
Currently as per the request, I m working on, when ever the new database created on the server, it should be added to AlwaysOn group.
Here I have written a code in the below way,
:Connect NODE1
BACKUP DATABASE [DB1] TO DISK = N'\\NODe1\ag-sp1p\DB.bak' WITH COPY_ONLY, FORMAT, INIT, SKIP, REWIND, NOUNLOAD, COMPRESSION, STATS = 5
GO
:Connect NODE2
RESTORE DATABASE [DB1] FROM DISK = N'\\NODE1\ag-sp1p\DB.bak' WITH NORECOVERY, NOUNLOAD, STATS = 5
GO
Issue:
The above code working normally with in the cursor it is/was failing
Cursor Code would be like below:
:Connect NODE1
BACKUP DATABASE @name TO DISK @filename
GO
:Connect NODE2
RESTORE DATABASE @name FROM DISK = @filename
GO
Error:
Backup location is taking like with default backup location
EG: Default Location: C:\Programfiles\MSSQL\Backup\\\NODe1\ag-sp1p\DB.bak' WITH COPY_ONLY, FORMAT, INIT, SKIP, REWIND, NOUNLOAD, COMPRESSION, STATS = 5
hence the above location is not valid, the query not executing.
Please suggest.
Thanks,
Satish Kumar.
Thanks, Satish Kumar. Please mark as this post as answered if my anser helps you to resolves your issue :)