Solved

error on t-sql script

Posted on 2016-08-24
3
19 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Partially Contained Databases - Cross Database Queries 3 43
Authentication error 1 38
Error in query 3 52
Need help debbuging stored procedure 21 32
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 …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

932 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

17 Experts available now in Live!

Get 1:1 Help Now