我用SQL Server 2000 作为数据库,数据库名为:Password_Test;Delphi 7 进行数据库备份和还原时遇到了这么个错误提示:
Project DB_Backup_Pro.exe raised exception class EOleException with message '第1行:'d:back1.bak'附近有语法错误。',
Process stopped. Use Step or Run to continue.
可是我检查了我的源程序很久没能找出来,但是在SQL Server 2000分析器中进行都成功。
源代码如下:procedure TDB_Backup.BitBtn2Click(Sender: TObject);
begin
adoquery1.Close;
adoquery1.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=Password_Test;Data Source=Hello World';
try
with adoquery1 do
begin
close;
sql.Clear;
//还原数据库
sql.Add('restore database Password_Test from disk ="d:\back1.bak"');
execsql;
end;
showmessage('还原成功。');
except
on e:exception do
showmessage('还原失败。');
end;
end;procedure TDB_Backup.BitBtn1Click(Sender: TObject);
var str:string;
begin
adoquery1.Close;
adoquery1.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=Password_Test;Data Source=Hello World';
try
with adoquery1 do
begin
close;
sql.Clear;
//备份数据库
sql.Add('backup database Password_Test to disk="d:\back1.bak" with init');
execsql;
end;
showmessage('备份完成。');
except
on e:exception do
showmessage('备份失败。');
end;
end;
Project DB_Backup_Pro.exe raised exception class EOleException with message '第1行:'d:back1.bak'附近有语法错误。',
Process stopped. Use Step or Run to continue.
可是我检查了我的源程序很久没能找出来,但是在SQL Server 2000分析器中进行都成功。
源代码如下:procedure TDB_Backup.BitBtn2Click(Sender: TObject);
begin
adoquery1.Close;
adoquery1.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=Password_Test;Data Source=Hello World';
try
with adoquery1 do
begin
close;
sql.Clear;
//还原数据库
sql.Add('restore database Password_Test from disk ="d:\back1.bak"');
execsql;
end;
showmessage('还原成功。');
except
on e:exception do
showmessage('还原失败。');
end;
end;procedure TDB_Backup.BitBtn1Click(Sender: TObject);
var str:string;
begin
adoquery1.Close;
adoquery1.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=Password_Test;Data Source=Hello World';
try
with adoquery1 do
begin
close;
sql.Clear;
//备份数据库
sql.Add('backup database Password_Test to disk="d:\back1.bak" with init');
execsql;
end;
showmessage('备份完成。');
except
on e:exception do
showmessage('备份失败。');
end;
end;
解决方案 »
- 高分请教奇怪的Ado的Lookup类型字段问题
- 各位大侠,帮帮忙呀.三层数据连接问题
- 菜鸟求救~!Rave报表中做主从报表.....
- 请问:用delphi连MSSQL2000,怎样提高连接效率?
- frame 问题
- ehom的亿合软件
- 关于dll和api的问题
- 使用Delphi的TMediaPlayer控件定制能播放实况视频流的媒体播放器!
- stringgrid能否进行竖行统计?如何统计?
- 错误?错误!‘Could't perform the edit because another user changed the record’multipe record found,but only one was except
- 使用TREEVIEW显示两个有关系的表时出现问题
- 怎样把768*576的avi录像,利用tmediaplayer以384*288的区域显示出来?
...
...procedure TDB_Backup.BitBtn2Click(Sender: TObject);
begin
adoquery1.Close;
adoquery1.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=Master;Data Source=Hello World'; //此行改
try
with adoquery1 do
begin
close;
sql.Clear;
//还原数据库
sql.Add('restore database Password_Test from disk ='+Quotedstr('d:\back1.bak'));//此行改
execsql;
end;
showmessage('还原成功。');
except
on e:exception do
showmessage('还原失败。');
end;
end;procedure TDB_Backup.BitBtn1Click(Sender: TObject);
var str:string;
begin
adoquery1.Close;
adoquery1.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=Password_Test;Data Source=Hello World';
try
with adoquery1 do
begin
close;
sql.Clear;
//备份数据库
sql.Add('backup database Password_Test to disk='+Quotedstr('d:\back1.bak')+' with init'); //此行改
execsql;
end;
showmessage('备份完成。');
except
on e:exception do
showmessage('备份失败。');
end;
end;
但是我有一点还要问一下为什么还原数据库的时候要将Initial Catalog改成Master呢??!