安装完sql2000后,如何安装数据库呢(100分)

  • 主题发起人 主题发起人 fscdc4
  • 开始时间 开始时间
F

fscdc4

Unregistered / Unconfirmed
GUEST, unregistred user!
安装完sql2000后,如何安装数据库,我的代码是:<br>procedure TserverForm.restore5(file1:string);<br>var sqlstr,backup11,database1,restoretext,cur_dir:string;<br>begin<br>&nbsp; &nbsp;cur_dir:=getdir(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//取得当前目录<br>&nbsp; &nbsp;database1:='syjxc';<br>&nbsp; &nbsp;restoretext:='restore database syjxc from disk='+quotedstr(file1);<br>&nbsp; &nbsp;ADOQuery2.Connection.BeginTrans;<br>&nbsp; &nbsp;with ADOQuery2 do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;close;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sql.clear;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sql.Add('use master'); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //设置当前数据库为master<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sql.Add('ALTER DATABASE syjxc SET OFFLINE WITH ROLLBACK IMMEDIATE'); &nbsp;//分离数据库<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sql.Add(restoretext); &nbsp; &nbsp; &nbsp;//还原数据库<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sql.Add('ALTER DATABASE syjxc SET ONLINE WITH ROLLBACK IMMEDIATE'); &nbsp; //重新连接数据库<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;execsql;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp;ADOQuery2.Connection.CommitTrans;<br>&nbsp; &nbsp;chdir(cur_dir); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //恢复当前目录<br>end;<br>procedure TserverForm.cre_syjxc(db_name:string);<br>var sqlstr,backup11,database1:string;<br>//设置ADOQuery1链接数据库master,或动态链接<br>begin<br>&nbsp; SQLStr := 'select * from sysdatabases where name = '+ quotedStr(db_name);<br>&nbsp; with ADOQuery2 do<br>&nbsp; begin<br>&nbsp; &nbsp; Close;<br>&nbsp; &nbsp; SQL.Clear;<br>&nbsp; &nbsp; SQL.add(SQLStr);<br>&nbsp; &nbsp; Open;<br>&nbsp; &nbsp; if ISEmpty then<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SQLStr := 'Create Database '+db_name;//具体可参考MSSql<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Close;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SQL.Clear;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SQL.add(SQLStr);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ExecSQL;<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; end;<br>end;<br>function TserverForm.getdir():string;//取当前目录<br>var CDir:string;<br>begin<br>&nbsp; &nbsp;setlength(CDir,144);<br>&nbsp; &nbsp;if GetCurrentdirectory(144,pchar(cdir))&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp; setlength(cdir,strlen(pchar(cdir)))<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; raiselastwin32error;<br>&nbsp; &nbsp;result:=CDir;<br>end;<br><br>procedure TserverForm.FormActivate(Sender: TObject);<br>var cur_dir,file1:string;<br>begin<br>&nbsp; &nbsp;cre_syjxc('syjxc'); &nbsp; &nbsp; &nbsp; &nbsp;//建立syjxc<br>&nbsp; &nbsp;cur_dir:=getdir();<br>&nbsp; &nbsp;file1:=cur_dir+'/数据库文件/syjxc';<br>&nbsp; &nbsp;showmessage('服务器安装完毕');<br>&nbsp; &nbsp;close;<br>end;<br>//数据库是当前目录下的 数据库文件/syjxc<br>程序运行的结果是 建立了syjxc数据库,但没有把 数据库文件/syjxc 还原到数据库syjxc中,没有还原,但是如果用手工建立syjxc,,再运行以上程序的话,就可以还原。注:syjxc是备份出来的数据库,请问我如何修改以上的程序才能建立数据库syjxc,再还原呢
 
直接用存储过程不行吗?<br>sp_attach_db '数据库名'<br>&nbsp; &nbsp; '路径/syjxc.MDF',<br>&nbsp; &nbsp; '路径/syjxc.LOG'
 
只有syjxc文件,没有syjxc.MDF和syjxc.LOG文件,syjxc是用企业管理器备份出来的
 
只有syjxc文件,没有syjxc.MDF和syjxc.LOG文件,syjxc是用企业管理器备份出来的,请给出详细的代码
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
465
import
I
后退
顶部