Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 !!!
Posted
Updated 14-Sep-13 8:12am
v2

1 solution

You can use the restore command for restoring
like this:
SQL
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:
SQL
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);
 
Share this answer
 
v2
Comments
Emad Hassan Khan 15-Sep-13 9:38am    
it shows an error "this session is already in used please use master database"
Mehdy Moini 15-Sep-13 12:49pm    
your connectionstring must be with master database:

http://technet.microsoft.com/en-us/library/ms186858.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900