全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:971
推到 Plurk!
推到 Facebook!

关于SQL SERVER RESTORE 后不能直接存取资料的问题

缺席
Nete2
一般會員


發表:1
回覆:1
積分:0
註冊:2007-04-08

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-04-09 00:32:01 IP:69.156.xxx.xxx 訂閱
各位前辈,我的问题是,delphi 用‘restore database..’ 后,我的program不可以直接access 任何table, 报告 ‘invalid object name’,但exit 我的program,重新run
后,就可以直接access 任何table,不知我的错误在那里。下边是malanlk的restoreDB,及我的部分program
Reference: http://delphi.ktop.com.tw/board.php?cid=30&fid=66&tid=77945
From malanlk
function TFrmBackup.RestoreDB(strDBName,strFileName: string): boolean;
var
strSQL: string;
begin
Result := false;
strSQL := 'RESTORE DATABASE [' strDBName '] FROM DISK = N''' strFileName ''' WITH FILE = 1, NOUNLOAD , STATS = 10, RECOVERY, REPLACE';

try
ADODataSetWho.Recordset := connAdo_res.Execute('sp_who');
ADODataSetWho.First;
while not ADODataSetWho.Eof do
begin
if ADODataSetWho.FieldByName('dbname').AsString = strDBName then
begin
MessageBox(Application.Handle,Pchar('Database ' strDBName 'is in use by ' ADODataSetWho.FieldByName('loginame').AsString '!'),'Restore Error',MB_OK MB_ICONERROR);
Exit;
end;
ADODataSetWho.Next;
end;
connAdo_res.Execute(strSQL);
except
MessageBox(Application.Handle,'Restore Database Error!','It Is Error',MB_OK MB_ICONERROR);
Exit;
end;
Result := true;
end;

----- following are parts of my program ------
....
RestoreDB('MyDBSQL', 'd:\Shared\EmptyDB.bak');
//Re-connect again after restore
ADOConnectionOne.Close;
try
ADOConnectionOne.Open;
except
on Exception do begin
...
end;
end;
//test
if ADOConnectionOne.Connected then begin
ADOQueryIt.Close;
ADOQueryIt.SQL.Clear;
ADOQueryIt.SQL.Add('SELECT * FROM Sales WHERE TotalAmt <> 0');
ADOQueryIt.Open;
end;

when stepping into ADOQueryIt.Open; 'Invalid object name' shows

谢谢

Nete2
一般會員


發表:1
回覆:1
積分:0
註冊:2007-04-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-04-09 14:50:01 IP:69.156.xxx.xxx 訂閱
I detach the Backup/Restore from the program, to make it alone to avoid above problem.maybe that is a easier way to make the program work.
系統時間:2024-05-19 14:42:52
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!