自动附加Sqlserver数据库

procedure TfrmMain.RestoreDataBase;
var
  CmdStr,
  Paths:String;
begin
  Paths:=Extractfilepath(Application.ExeName);
  if fileexists(ConCat(Paths,'数据库文件名称')) then
    try
    CmdStr:='ISQL -E -Q "if (select Count(*) from sysdatabases where name=%s)=0 EXEC sp_attach_db @dbname = N%s,@filename1 = N%s,@filename2 = N%s"';
    CmdStr:=format(CmdStr,[ConCat(#39,'NGISdbms',#39),
                           ConCat(#39,'数据库名称',#39),
                           ConCat(#39,Paths,'数据库文件名称',#39),
                           ConCat(#39,Paths,'数据库日志文件名称',#39)]);
    WinExec(PChar(CmdStr),0);
    except
    on E:Exception do
      Logmemo.Add(e.Message);
    end;
end;

转载于:https://www.cnblogs.com/caowei-it/archive/2013/01/06/4145802.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值