怎么附加一个sql server2000数据库,
例数据库文件就放在d:\data\my_datadase
要怎么附加,我想要这代码。。。。谢谢
------解决方案--------------------
sqlca.autocommit = true
string Ls_MySql
Ls_MySql = "sp_attach_db '数据库名','d:\data\my_datadase\数据库名.mdf','d:\data\my_datadase\日志名.ldf'"
EXECUTE IMMEDIATE :Ls_MySql USING sqlca;
if sqlca.sqlcode <> 0 then
RollBack;
Messagebox("","附加失败")
Return
end if
sqlca.autocommit = false
------解决方案--------------------
这里有备份的代码,思路参考一下
if FileExists ( sle_path.text ) then
if messagebox("提示信息","今天已经备份过数据库,是否覆盖?",question!,yesno!)=2 then return
FileDelete ( sle_path.text)
end if
st_4.text ="正在备份数据......."
string ls_path ,ls_use
ls_use = 'EXEC'+'('+"'USE "+sle_db.text+"'"+')'
EXECUTE IMMEDIATE :ls_use ;
ls_path = sle_path.text
SQLCA.AutoCommit = TRUE
ls_use = "EXEC sp_addumpdevice 'disk'"+" , '"+sle_db.text+"' , "+" '"+ls_path+"'"
EXECUTE IMMEDIATE : ls_use ;
ls_use ="BACKUP DATABASE "+sle_db.text+" to "+sle_db.text+""
EXECUTE IMMEDIATE : ls_use ;
ls_use = "exec sp_dropdevice '"+sle_db.text+"'"
EXECUTE IMMEDIATE : ls_use ;
//newbakdat
setprofilestring('yy.ini','settings','newdat',ls_path)
SQLCA.AutoCommit = false
if sqlca.sqlcode = 0 then
messagebox("system ok!","数据库成功备份于 '"+sle_path.text+"'!")
close(w_backup)
HALT CLOSE
else
messagebox("system",sqlca.sqlerrtext)
rollback;
close(w_backup)
//HALT CLOSE
end if
------解决方案--------------------
------解决方案--------------------
我有附加数据和有关数据库操作的示例,如果需要可以发至邮箱
------解决方案--------------------
ls_sql = " EXEC sp_attach_single_file_db " + DatabaseNames + ", '"+tab_1.tabpage_1.mle_selected.text +"'"
EXECUTE IMMEDIATE :ls_sql;
commit;
只附加MDF文件,不附加日志文件。