Solved

error on t-sql script

Posted on 2016-08-24
3
17 Views
Last Modified: 2016-08-25
Hello,

I try to build a backup command but the default backup directory is specified :
DECLARE @FILE VARCHAR(65)
DECLARE @DUMPFILE VARCHAR(150)

SELECT CONVERT(VARCHAR(10),GETDATE(),112)
SELECT CONVERT(VARCHAR,GETDATE(),108)
SELECT REPLACE(CONVERT(VARCHAR,GETDATE(),108),':','')

SET @FILE = CONVERT(VARCHAR(10),GETDATE(),112) + '_' + REPLACE(CONVERT(VARCHAR,GETDATE(),108),':','')
SELECT @FILE
SET @DUMPFILE = '''' + 'd:\backup' + @FILE + '.bak' + ''''
SELECT @DUMPFILE



BACKUP database model 
to disk=@DUMPFILE
with compression, copy_only

Open in new window


DECLARE @FILE VARCHAR(65)
DECLARE @DUMPFILE VARCHAR(150)

SELECT CONVERT(VARCHAR(10),GETDATE(),112)
SELECT CONVERT(VARCHAR,GETDATE(),108)
SELECT REPLACE(CONVERT(VARCHAR,GETDATE(),108),':','')

SET @FILE = CONVERT(VARCHAR(10),GETDATE(),112) + '_' + REPLACE(CONVERT(VARCHAR,GETDATE(),108),':','')
SELECT @FILE
SET @DUMPFILE = '''' + 'd:\backup' + @FILE + '.bak' + ''''
SELECT @DUMPFILE



BACKUP database test
to disk=@DUMPFILE
with compression, copy_only

Msg 3201, Level 16, State 1, Line 15
Cannot open backup device 'E:\MSSQLSQL01\BACKUP\'d:\backup20160824_180424.bak''. Operating system error 123(failed to retrieve text for this error. Reason: 15105).
Msg 3013, Level 16, State 1, Line 15
BACKUP DATABASE is terminating abnormally.


Why?

Thanks

Regards
0
Comment
Question by:bibi92
  • 2
3 Comments
 
LVL 1

Expert Comment

by:Helen Ramsden
ID: 41769113
Hi

Please could you try removing two apostrophes from the beginning and end. e.g.

SET @DUMPFILE = '' + 'd:\backup' + @FILE + '.bak' + ''

Thanks,
Helen
0
 
LVL 1

Accepted Solution

by:
Helen Ramsden earned 500 total points
ID: 41769142
Also, if you want the backup to be saved to the backup folder, add an oblique to the directory e.g.

SET @DUMPFILE = '' + 'd:\backup\' + @FILE + '.bak' + ''
0
 

Author Comment

by:bibi92
ID: 41771313
Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now