简体   繁体   English

数据库备份失败

[英]Database backup not succeeding

I'm trying to backup my database but nothing happens when i try to backup, but if i hard-code the path it works. 我正在尝试备份我的数据库,但是当我尝试备份时什么也没有发生,但是如果我对路径进行硬编码的话。

This method works with hard coded file path. 此方法适用于硬编码的文件路径。

dbBackup.Devices.AddDevice(@"C:\Backup\saveFile.bak", DeviceType.File);

But i tried the second, the one i want the user to input the file path but it does not work and the input is exactly the same. 但是我尝试了第二个,我希望用户输入文件路径,但是它不起作用并且输入是完全相同的。

dbBackup.Devices.AddDevice(@"'"+ txtPath.Text +"'", DeviceType.File);

Adding quotes similar to how this is done with a direct T-SQL command is not necessary. 不需要添加类似于使用直接T-SQL命令完成此操作的引号。 The string will be correctly parsed without these. 没有这些字符串将被正确解析。 Given that the text from the hard-coded value and user input is the same as specified in your post, the following will return the same result for both. 鉴于硬编码值和用户输入中的文本与您的帖子中指定的文本相同,以下内容将为两者返回相同的结果。

dbBackup.Devices.AddDevice(txtPath.Text, DeviceType.File);

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

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