如何在winforms中执行存储过程? [英] How to execute stored procedure in winforms ?
问题描述
其实我在winforms中制作导入和导出数据库选项!我在winforms中使用连接架构...我的数据库驻留在sql management studio 2012中!我的问题是:
1 - 如何在ssms 2012中创建存储过程,通过该存储过程我可以恢复当前活动数据库的备份,同时覆盖当前数据恢复数据库备份???
2 - 如何在我的winforms应用程序中使用此存储过程?
注意:我的备份数据库存储过程在winforms中工作正常!!!
您可以使用restore命令恢复
之类的这:
创建 proc as 将
恢复为
开始
恢复 数据库'mydatabasename'
从 disk ='path dirrectory'
使用替换
结束
但请注意您的备份文件名必须与您的数据库文件名或
如果没有,您需要将文件备份到数据库文件明确:
create proc resotre as
开始
恢复 数据库'mydatabasename'
从 disk ='path dirrectory'
使用替换
Move'filename backup' 'dirictory 数据库文件'
将'文件名备份'移至'dirictory 数据库文件'
结束
和轻松调用proc
在sql命令参数中调用它:
SqlCommand testCMD = new SqlCommand
(TestProcedure,PubsConn);
Actually i am making import and export database option in winforms ! i am using connected architecture in winforms ... my database resides in sql management studio 2012 ! my question are :
1 - how to make a stored procedure in ssms 2012 through which i can restore the backup of my current active database while overwriting the current data with targeted restoration database backup ???
2 - how to use this stored procedure in my winforms app ?
NOTE: my backup database stored procedure is working fine in winforms !!!
You can use the restore command for restoring
like this:
create proc as restoring as begin Restore database ‘mydatabasename’ From disk=’path dirrectory’ With replace end
but please note your back up file name must have same name as your database file name or
if not, you need to assign back up files to database file explicity:
create proc resotre as begin Restore database ‘mydatabasename’ From disk=’path dirrectory’ With replace Move’filename backup’ to ‘dirictory of database file’ Move ‘filename backup’ to ‘dirictory of database file’ end
and for calling proc easily
call it in sql command parameter:
SqlCommand testCMD = new SqlCommand ("TestProcedure", PubsConn);
这篇关于如何在winforms中执行存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!