我用delphi2005+sql2000,如果一步一步执行程序,那OK,可是直接运行就有问题了。代码如下:主要目的是先关闭sql服务,再复制数据库,再打开sql服务管理
代码:
var
s1,s2:string;
begin
if edit1.text<>'' then
try
//关闭sql服务
  winexec(pchar('cmd.exe   /c   net   stop   '+'mssqlserver'),sw_hide);
except
  messagedlg('关闭sql服务不成功!',mterror,[mbyes],0);end;
//备份
try
s1:= extractfilepath(paramstr(0))+'data\salary_Data.MDF';
s2:= extractfilepath(paramstr(0))+'data\salary_Log.LDF';
copyfile(pchar(s1),pchar(edit1.Text+'salary_Data.MDF'),true);
copyfile(pchar(s2),pchar(edit1.Text+'salary_Log.LDF'),true);
except
  messagedlg('数据库还原不成功!',mterror,[mbyes],0);
end;
//打开sql服务
try
winexec(pchar('cmd.exe   /c   net   start   '+'mssqlserver'),sw_hide);
except
  messagedlg('打开sql服务不成功!',mterror,[mbyes],0);end;
messagedlg('数据库还原成功!',mtconfirmation,[mbyes],0);
application.Terminate;