简体   繁体   English

SQL Server:备份错误

[英]SQL Server : Backup Error

When we are trying to backup our database we get an error. 当我们尝试备份数据库时,出现错误。

Front End         : VB.Net
Back End          : SQL Server
DB Name           : PROFITSTORAGE
Backup Location   : 'D:\Profit\Data\ProfitStorage.Bak'

Code: Dim con As New SqlConnection Dim query As SqlCommand 代码:Dim con作为新的SqlConnection Dim查询作为SqlCommand

    Try
        con.ConnectionString = "Server=(LocalHost);Data Source=LocalHost\SQLEXPRESS;Integrated Security=SSPI"
        con.Open()
        query = con.CreateCommand
        query.CommandText = "BACKUP DATABASE PROFITSTORAGE TO DISK='D:\Profit\Data\ProfitStorage.bak' WITH INIT"
        query.ExecuteNonQuery()
        query.Dispose()
        con.Close()
    Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Backup Failed")
    End Try

Query used : 使用的查询:

BACKUP DATABASE PROFITSTORAGE 
TO DISK='D:\Profit\Data\ProfitStorage.bak' WITH INIT

Error Message : 错误信息 :

Cannot open backup device 'D:\\Profit\\Data\\ProfitStorage.bak'. 无法打开备份设备“ D:\\ Profit \\ Data \\ ProfitStorage.bak”。 Operating system error 3 (failed to retrieve text for this error. Reason: 15105). 操作系统错误3(未能为此错误检索文本。原因:15105)。
BACKUP DATABASE is terminating abnormally. BACKUP DATABASE异常终止。

How to sort out this issue? 如何解决这个问题?

The query is not creating the folder if its not existing. 如果该文件夹不存在,则查询不会创建该文件夹。
We should create a folder manually instead. 我们应该手动创建一个文件夹。
Since we are using VB.Net we had to create a folder with the following code before backup: 由于我们使用的是VB.Net,因此必须在备份之前使用以下代码创建一个文件夹:

                My.Computer.FileSystem.CreateDirectory("D:\Profit\Data\")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM