Answer the question
In order to leave comments, you need to log in
Why does MS SQL server 2008 R2 add extra characters to TSQL script?
Hello!
We back up the database using a script (bukh - database name, '\\192.168.10.2\bukh\bukh - network share)
DECLARE @Nw3 NVARCHAR(512)
SET @Nw3 = '\\192.168.10.2\bukh\bukh_ ' + Convert(varchar(8), GETDATE(), 112) + '.bak'
BACKUP DATABASE [bukh] TO DISK = @Nw3 WITH NOFORMAT, INIT, NAME = N'db_backup', SKIP, NOREWIND, NOUNLOAD,compression, STATS = 10
per network share. Recently the script stopped working. I look in the logs, and in them
the request execution failed "DECLARE @Nw3 NVARCHAR (512)
SET @Nw3 = '\\\\192.168.10..." with the following error: "Unable to open backup device '\\\\192.168.10.2\\bukh\\bukh_20170720.bak'. Operating system error 64 (The specified network name is no longer available.).
BACKUP DATABASE aborted with an error." Possible causes of failure: problems with this query, the 'ResultSet' property was not set correctly, the parameters were set incorrectly, or the connection was not established correctly.
Extra slashes appear to have been added. Why is this happening?
Answer the question
In order to leave comments, you need to log in
How did it work before? What starts the script? So the sql server is a dumb beast and does not add anything to the script code.
Is the \\192.168.10.2\bukh resource available?
Try changing
SET @Nw3 = '\\192.168.10.2\bukh\bukh_' + Convert(varchar(8), GETDATE(), 112) + '.bak'
to
SET @Nw3 = N'\\192.168.10.2\bukh \bukh_' + Convert(nvarchar(8), GETDATE(), 112) + N'.bak'
Now after adding N, here is the error:
Executing the query "DECLARE @Nw3 NVARCHAR(512)
SET @Nw3 = N'\\\\192.168.10.2\\bukh\\bukh_' + Convert(varchar(8), GETDATE() , 112) + N'.bak'
BACKUP DATABASE [bukh] TO DISK = @Nw3 WITH NOFORMAT, INIT, NAME = N'db_backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10" failed with the following error: "Cannot open backup device '\\\\192.168.10.2\\bukh\\bukh_20170724.bak'. Operating system error 5(Permission denied.).
BACKUP DATABASE is terminating abnormally.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question