備份與恢復如下:function Db_Backup(db_Name,file_Name:string):integer; var user_Query:TADOQuery; sql_txt:string; begin try sql_txt:='Backup database ' + db_Name + ' to disk='''+file_Name+''' with init'; user_Query:=TADOQuery.Create(Application); with user_Query do begin ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=225421;Data Source=SCOTT-9EMADTTKA'; SQL.Text:='USE gold_callback'; ExecSQL(); SQL.Text:=sql_txt; ExecSQL(); Close; end; Result:=1; exit; except Result:=0; end; end;function Db_Restore(db_Name,file_Name:string):integer; var user_Query:TADOQuery; sql_txt:string; begin try sql_txt:='Restore database ' + db_Name + ' from disk='''+file_Name+''' with replace'; user_Query:=TADOQuery.Create(Application); with user_Query do begin ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=********;Data Source=your'pc name'; SQL.Text:='USE gold_callback'; ExecSQL(); // Connection:=Data_Link_Source.GTL_ADOCnt; SQL.Text:=sql_txt; // Prepared:=true; ExecSQL(); // Close; end; Result:=1; exit; except Result:=0; end;end;
backup 和restore是用于恢复数据库文件的,我想实现的是如何恢复数据库表?请问如何实现?
我知道了,用 select * into 表名 in ''e:\database.mdb'' from 表名 where 条件 这是备份实现,要注意的是备份时,目标数据库中不能有存在的目标表!恢复时,把源表删了,在执行上述的反操作就行了。
tabby(内存泄漏): 按你说的做怎么不行啊,用的是SQLServer7.0吗, 执行: select * into Functree1 in ''C:\temp\Functree1.mdb'' from Functree 提示: Server: Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'in'.
你是在什么地方执行的这句sql语句阿? 我是用 ADOQuery 中执行的,如果你在sqlserver里面执行的话,可能要改写成: select * into Functree1 in 'C:\temp\Functree1.mdb' from Functree
restore 在sql server里查具体的用法
如果是 access ,vfp 完全可以复制文件
var
user_Query:TADOQuery;
sql_txt:string;
begin
try
sql_txt:='Backup database ' + db_Name + ' to disk='''+file_Name+''' with init';
user_Query:=TADOQuery.Create(Application);
with user_Query do
begin
ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=225421;Data Source=SCOTT-9EMADTTKA';
SQL.Text:='USE gold_callback';
ExecSQL();
SQL.Text:=sql_txt;
ExecSQL();
Close;
end;
Result:=1;
exit;
except
Result:=0;
end;
end;function Db_Restore(db_Name,file_Name:string):integer;
var
user_Query:TADOQuery;
sql_txt:string;
begin
try
sql_txt:='Restore database ' + db_Name + ' from disk='''+file_Name+''' with replace';
user_Query:=TADOQuery.Create(Application);
with user_Query do
begin
ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=********;Data Source=your'pc name';
SQL.Text:='USE gold_callback';
ExecSQL();
// Connection:=Data_Link_Source.GTL_ADOCnt;
SQL.Text:=sql_txt;
// Prepared:=true;
ExecSQL();
// Close;
end;
Result:=1;
exit;
except
Result:=0;
end;end;
select * into 表名 in ''e:\database.mdb'' from 表名 where 条件
这是备份实现,要注意的是备份时,目标数据库中不能有存在的目标表!恢复时,把源表删了,在执行上述的反操作就行了。
按你说的做怎么不行啊,用的是SQLServer7.0吗,
执行:
select * into Functree1 in ''C:\temp\Functree1.mdb''
from Functree
提示:
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'in'.
我是用 ADOQuery 中执行的,如果你在sqlserver里面执行的话,可能要改写成:
select * into Functree1 in 'C:\temp\Functree1.mdb' from Functree
我是在SQLServer中执行的,还是同样的提示,
如果可能的话,你在SQLServer中试一下,然后
告诉我,谢了