VB.NET - backup and retore of sql-server database in vb.net.

Asked By Deepak Ghule
09-Jun-08 09:21 AM

How to take backup of sql-server database in vb.net.

And how to retore it using vb.net.

 

 

hi...  hi...

09-Jun-08 09:45 AM

Hi,

here is the nice article for this..

http://www.codeproject.com/KB/dotnet/SQL_Server_backup.aspx

hi  hi

09-Jun-08 11:40 AM
create a backup file using the following code
Dim a As SQLDMO.Backup
Dim svr As SQLDMO._SQLServer
Try
a = New SQLDMO.BackupClass()
svr = New SQLDMO.SQLServerClass()

svr.LoginSecure = False
svr.Connect(ServerName, ADMIN_UID, ADMIN_PWD)

a.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database
a.Database = dbName
a.Files = path & BACKUP_FILE
a.BackupSetName = dbName
a.BackupSetDescription = "Database backup"
a.Initialize = True
a.SQLBackup(svr)

svr.DisConnect()
svr = Nothing
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try

reply  reply

09-Jun-08 12:01 PM

To restore the below code will help you...

Dim restore As SQLDMO.Restore
Dim svr As SQLDMO._SQLServer

Try
restore = New SQLDMO.RestoreClass()
svr = New SQLDMO.SQLServerClass()

svr.LoginSecure = False
svr.Connect(ServerName, ADMIN_UID, ADMIN_PWD)

restore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database
restore.Database = dbName
restore.Files = path & BACKUP_FILE
restore.FileNumber = 1
restore.SQLRestore(svr)

svr.DisConnect()
svr = Nothing
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try

Also see this link below, it will help you...

http://www.shabdar.org/sql-server-backup-utility.html

using SQL-DMO  using SQL-DMO
09-Jun-08 12:46 PM

Here is the link where you can find the sample code, I think this is exactly what you want!

Simple Backup/Restore Utility With SQL-DMO Using VB.NET

http://www.aspfree.com/c/a/VB.NET/Simple-BackupRestore-Utility-With-SQLDMO-Using-VBNET/

check this..  check this..
09-Jun-08 11:32 PM

You can check this for more detailed backup activity that can be done in VB.net ..

http://www.c-sharpcorner.com/UploadFile/shabdarghata/sql-server-backup-utility-sql-dmo02042008134007PM/sql-server-backup-utility-sql-dmo.aspx

and these for more info..(including code given)

http://www.shabdar.org/sql-server-backup-utility.html

 

For that Use SQL-DMO library  For that Use SQL-DMO library
10-Jun-08 12:21 AM

like;

'Server object from SQL-DMO library
Dim oServer As New SQLServer2
'Database object from SQL-DMO library
Dim db As SQLDMO.Database2
'BCP Utility from SQL-DMO Library
Dim objBCP As New SQLDMO.BulkCopy2

Function for exporting data to a file from SQL server

objBCP.DataFilePath = "c:\temp\EmployeeData.dat"
db.Tables.Item("Employee").ExportData(objBCP)
Generating SQL script for an SQL server object
'Generate script with drop statement
Dim SQL as String = db.GetObjectByName("Employee").Script_
(SQLDMO_SCRIPT_TYPE.SQLDMOScript_Drops) + db.GetObjectByName("Employee").Script()
For more details just go thr this link which will explain you step wise details to do same
http://www.codeproject.com/KB/dotnet/SQL_Server_backup.aspx
http://www.shabdar.org/sql-server-backup-utility.html
Best Luck!!!!!!!!!!
Sujit.
a  a
01-Jul-08 01:21 AM
a
Create New Account
help
LCS2005 SP1 Backup Error Windows 7 Hello, We used to have automatic scheduled task to backup the LCS Standard edition (running on SQL Desktop Edition). However, it looks like it hasn't been backing up the database for run the command directly, i get the following: - -- -- -- -- -- -- -- -- -- -- C: \ > "C: \ Program Files \ Microsoft LC 2005 \ Server \ Support \ dbbackup.exe" / backupfile:"C: \ LC \ LC Backup" Connecting to SQL Server. . . Performing backup. . . Error: Failed to backup database. SQL Error: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid
SQL Server Backup SQL Server I am on SQL Server 2000. My application which connects to databases in sql serve instance has been shut down. If I do a full backup of all databases
Backup on Sql server A and restore to Sql server B SQL Server Hi! I have two SQL Server 2008 Std (Sql Server A and Sql Server B) on Windows Server 2008 R2
the way to backup SQL Server SQL Server Hi, I am going to setup new Windows 2003 R2 server and SQL 2005. Is it save to use the Windows Backup to backup the complete server including the SQL? What is the procedues? Thanks very much
Attach SQL Server 2008 database to SQL Server 2000 Server SQL Server Hi, I have created a database in SQL Server 2008, with compatibility level of SQL Server 2000. Now when I detach the DB