其实也不是很有挑战性,呵呵,只是我确实不知道怎么办了,不说废话了,现在问题总结如下.
问题一,我要在本地做一个客户端,连接的是远程的SQL Server 2000服务器.我需要在客户端做个备份恢复的程序,我的这一块的主要代码如下.
procedure TForm1.Button1Click(Sender: TObject);   //备份数据库
begin
    adoquery1.Close;
    adoquery1.ConnectionString:='Provider=SQLOLEDB.1;Password=3955742;Persist Security Info=True;User ID=sa;Initial Catalog=XYGL;Data Source=192.168.18.111';
    adoquery1.SQL.Clear;
    adoquery1.SQL.Add('backup database XYGL to disk = '+quotedstr('C:\MyBack.bak'));
    try
        adoquery1.ExecSQL;
        showmessage('Successful');
    except
        showmessage('fail');
    end;
end;procedure TForm1.Button2Click(Sender: TObject);     //恢复数据库
begin
    adoquery1.Close;
    adoquery1.ConnectionString:='Provider=SQLOLEDB.1;Password=3955742;Persist Security Info=True;User ID=sa;Data Source=192.168.18.111';
    adoquery1.SQL.Clear;
    adoquery1.SQL.Add('restore database XYGL from disk = '+quotedstr('C:\MyBack.bak'));
    try
        adoquery1.ExecSQL;
        showmessage('Successful');
    except
        showmessage('fail');
    end;
end;上面的代码,在窗体里面运行的时候,一点问题都没有,完全正确,但是由于需要,我现在需要把该窗体封装到动态链接库里面,于是我直接修改项目为Library,输出函数为ShowForm,
于是var
  Form1: TForm1;
  procedure ShowForm;export;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
    CoInitialize(nil);
    adoquery1.Close;
    adoquery1.ConnectionString:='Provider=SQLOLEDB.1;Password=3955742;Persist Security Info=True;User ID=sa;Initial Catalog=XYGL;Data Source=192.168.18.111';
    adoquery1.SQL.Clear;
    adoquery1.SQL.Add('backup database XYGL to disk = '+quotedstr('C:\MyBack.bak'));
    try
        adoquery1.ExecSQL;
        showmessage('Successful');
    except
        showmessage('fail');
    end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
    CoInitialize(nil);
    adoquery1.Close;
    adoquery1.ConnectionString:='Provider=SQLOLEDB.1;Password=3955742;Persist Security Info=True;User ID=sa;Data Source=192.168.18.111';
    adoquery1.SQL.Clear;
    adoquery1.SQL.Add('restore database XYGL from disk = '+quotedstr('C:\MyBack.bak'));
    try
        adoquery1.ExecSQL;
        showmessage('Successful');
    except
        showmessage('fail');
    end;
end;procedure ShowForm;export;
begin
    form1:=tform1.Create(nil);
    form1.ShowModal;
end;end.数据库备份和恢复的代码一点都没变,于是我用外部程序来调用这个动态链接库,这个时候问题来了,备份的时候是一点问题都没有的,但是我恢复的时候,也就是执行restore的时候,就会失败,症状是,也不报错,但是会一直停在adoquery1.ExecSQL(单步跟踪的结果)上,直到超时报错,后来我故意在里面设置一个语法错误,乖乖,一下子就报错了,证明我上面的会出现超时的代码是没有问题的,但是为什么会出现这种情况呢?该怎么解决呢?问题二,上面的代码执行备份的时候,只能把备份文件存放到远程服务器上的C盘,我怎么可能把该文件存到自己电脑上来呢.我就算执行ExtractFilePath(Application.ExeName)也不行.问题结束了,请各位大哥哥大姐姐一定要帮我一下啊.谢谢