Click here to Skip to main content
15,915,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!

I need help in vb.net!

How can i do a backup of database with SQLSERVER.SMO! I dont no where to start , i have seen example in codeproject but i need a siple way wich it means on click i button! also i need a restore in a simple way !


Thanks a lot!
Posted

hii

You can execute these scripts with sqlcommand

for backup

SQL
BACKUP DATABASE [Database name] TO DISK = N'Backup file path' WITH NOFORMAT, NOINIT,  NAME = N'Database backup name', SKIP, NOREWIND, NOUNLOAD,  STATS = 10


for restore

SQL
ALTER DATABASE [Database name] SET SINGLE_USER WITH ROLLBACK IMMEDIATE

SQL
RESTORE DATABASE [Database name] FROM DISK=N'Backup file path'

SQL
ALTER DATABASE [Database name] SET MULTI_USER


Make sure that CommandTimeout is enough for back or restore
 
Share this answer
 
Comments
Atmir 8-Oct-11 9:42am    
in VB.NET 2010 please ???
 
Share this answer
 
Comments
Atmir 8-Oct-11 9:43am    
i need for sql 2008R2 not 2005
André Kraak 8-Oct-11 9:53am    
The solution looks version independent, so give it a try.
Simon_Whale 9-Oct-11 14:19pm    
SQL 2008 also uses Smo objects for these sort of tasks too

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