"BACKUP DATABASE db_PWMS TO DISK='" + Str_dar + (System.DateTime.Now.ToShortDateString()).ToString() + MyMC.Time_Format(System.DateTime.Now.ToString()) + ".bak" + "'";
我用如上語句想備份數據庫,但是遇到問題,數據庫日志如下:
backup BACKUP 未能完成命令 BACKUP DATABASE db_PWMS TO DISK='C:\Users\dy01\Desktop\新建文件夾/2014/12/18150647.bak'
我覺得是”/“”\“的問題,因為我直接寫語句backup database db_PWMS to disk='C:/Users/dy01/Desktop/新建文件夾/333.bak' 是可以成功的
但是不知道如何解決,求大神指導
補充一下,Str_dar=folderBrowserDialog1.SelectedPath;
C:\Users\dy01\Desktop\新建文件夾/2014/12你的這個路徑不存在吧,你要先判斷下目錄存不存在,不存在用代碼創建按後在執行備份語句
string path = Str_dar + (System.DateTime.Now.ToShortDateString()).ToString() + MyMC.Time_Format(System.DateTime.Now.ToString());
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
string sql="BACKUP DATABASE db_PWMS TO DISK='" + path + ".bak" + "'";