Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hello guys! I am currently developing an inventory system. My system don't support any hard deleting. I wanted to include the feature of backing up the entire DB then clear the database for new records. But I just don't know how to code the copying DB. Any idea on how to do this? Thanks guys!
Posted

1 solution

Have a look at this: Backing up an SQL Database in C#[^] - it's in C#, but the code is pretty obvious and simple to translate.
 
Share this answer
 
Comments
gaga blues 2-Dec-12 9:50am    
I am currently trying the solution link that you gave me. I encountered an error like Backup failed for Server '<servername>'. I'm downloading the Hotfix for this now. Hope it will solve the problem. Thanks for the link!
OriginalGriff 2-Dec-12 10:04am    
I saw your post at the Tip itself and thought it was probably you! :laugh:

It may be that you have miss-translated from C# to VB - but you do need to know which line it is excepting on.
gaga blues 2-Dec-12 10:16am    
Yes it's me. I'm desperate :D
Here's the converted version of your code
Dim con As New ServerConnection("user\sqlexpress")
Dim server As New Server(con)
Dim source As New Backup()
source.Action = BackupActionType.Database
source.Database = "myDB"
Dim destination As New BackupDeviceItem(backUpFile, DeviceType.File)
source.Devices.Add(destination)
source.SqlBackup(server) //The exception is triggered here :(
con.Disconnect()
Anything wrong in this translated version that you see? :(
OriginalGriff 2-Dec-12 10:21am    
Server name.
Double check that it is USER\SQLEXPRESS - use SSMS to make certain.
gaga blues 2-Dec-12 10:25am    
I used the server explorer to come up with the user\sqlexpress. Here's the exact name in the server explorer. user\sqlexpress.myDB.dbo

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