|
-
May 2nd, 2007, 06:36 PM
#1
Thread Starter
New Member
backup database using VB
Hi all ...
Iam looking for a code on how to backup a database using VB.İt's urgent.
-
May 2nd, 2007, 11:32 PM
#2
Re: backup database using VB
Hi, Welcome to VBF !
what is the database that you are using...the simplest method would be just copying the database files to your backup folder...
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
May 3rd, 2007, 06:57 AM
#3
Re: backup database using VB
Welcome to the forums. 
If you are talking about Access, then bare in mind the database needs to be closed before it can be copied.
-
May 3rd, 2007, 07:13 AM
#4
Re: backup database using VB
And of course if this is MS SQL server you cannot copy the MDF or LDF - that would be a very bad practice...
See this thread
http://www.vbforums.com/showthread.p...t=backup+funds
and there are dozens of others that have discussed this as well.
-
May 4th, 2007, 05:48 PM
#5
Thread Starter
New Member
Re: backup database using VB
 Originally Posted by ganeshmoorthy
Hi, Welcome to VBF !
what is the database that you are using...the simplest method would be just copying the database files to your backup folder...
I am using Access.but actually ı need the code.ı know ı have to take a backup but how?ı need the code.
-
May 4th, 2007, 07:55 PM
#6
Re: backup database using VB
ganeshmoorthy already told you how.
 Originally Posted by ganeshmoorthy
the simplest method would be just copying the database files to your backup folder...
Just bare in mind that the database MUST be closed before you can copy it.
-
May 5th, 2007, 02:45 AM
#7
Re: backup database using VB
vb Code:
Private Sub Command1_Click()
Cn.Close 'close your connection or database object before copying
FileCopy SourceFileName, DestinationFileName 'this will copy the db file to your backup folder
End Sub
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
May 5th, 2007, 07:24 AM
#8
Thread Starter
New Member
Re: backup database using VB
 Originally Posted by ganeshmoorthy
vb Code:
Private Sub Command1_Click()
Cn.Close 'close your connection or database object before copying
FileCopy SourceFileName, DestinationFileName 'this will copy the db file to your backup folder
End Sub
what is cn?is it the name of the database?
do we just write the name of the source file name or the path of it?because ı have written the code but it didn't take the backup
-
May 5th, 2007, 09:14 AM
#9
Re: backup database using VB
cn is a connection object - based on the assumption that your program has code to work with the database. If that is not the case, simply leave that line out - but note that the FileCopy will fail if any program is using the database.
Whenever you are specifying file names (in FileCopy or anything else), you should specify the full path too, otherwise you are likely to work with the wrong files!
-
May 5th, 2007, 06:36 PM
#10
Thread Starter
New Member
Re: backup database using VB
 Originally Posted by si_the_geek
cn is a connection object - based on the assumption that your program has code to work with the database. If that is not the case, simply leave that line out - but note that the FileCopy will fail if any program is using the database.
Whenever you are specifying file names (in FileCopy or anything else), you should specify the full path too, otherwise you are likely to work with the wrong files!
I have written the code :
Cn.Close 'close your connection or database object before copying
FileCopy "d:\MY VİSUAL BASİC PROJECTS\U mObile\Database\db1", "c:\backup" 'this will copy the db file to your backup folder
where my database is in D in my visual basic projects
and the backup will be in C
however it still didn't work
ı am using database
but actually ı dınt understand what ıs connection object
because the form ı am using to take backup no dataobject is defined.So data connection is data ,ado things like that?
please find the solution its urgent
-
May 6th, 2007, 05:56 AM
#11
New Member
Re: backup database using VB
You can use the common dialogue control. Add the Microsoft Common Dialogue Control by right clicking the toolbox --> components --> then tick Microsoft Common Dialogue Control. put the common dialogue on your form Then use the code below:
Code:
Dim fso As Object, MyFile As Object
Set fso = CreateObject("Scripting.FileSystemObject")
CommonDialog.DialogTitle = " Back Up "
CommonDialog.Filter = "Microsoft Access Database (*.mdb)|*.mdb"
CommonDialog.ShowSave
If CommonDialog.FileName = "" Or mdiscreen.dlgCommonDialog.FileName = " " Then
MsgBox " You Must Type the Name For New Back up "
Else
Set MyFile = fso.GetFile(App.Path & "YOUR DATABASE PATH")
MyFile.Copy CommonDialog.FileName
MsgBox " BACK UP SUCESSFULLY COMPLETED ", vbInformation, "DataBase Backup"
End If
-
May 6th, 2007, 07:30 AM
#12
Re: backup database using VB
I don't think the common dialog is any use here, as it seems that the file name & path are pre-determined (but I could be wrong!).
I also think using FSO is overkill here - FileCopy is much simpler.
 Originally Posted by guncebertug
however it still didn't work
you should give us more info than that - did it give you an error? (if so, which one?), did it copy the file to somewhere else? ....
It seems to me that you haven't provided enough info to FileCopy, I think it should be like this:
Code:
FileCopy "d:\MY VİSUAL BASİC PROJECTS\U mObile\Database\db1.mdb", "c:\backup\db1.mdb"
ı am using database
but actually ı dınt understand what ıs connection object
because the form ı am using to take backup no dataobject is defined.So data connection is data ,ado things like that?
As you don't know already, you are not using a connection object - but it sounds as if you are using (evil!) data controls on your forms, which makes this (and many other things) much more difficult.
In this case, it means that you will probably not be able to copy the file while your program is running (or at least while other forms are open), as data controls stay connected to the database as long as the form they are on is loaded.
-
May 7th, 2007, 04:55 PM
#13
Re: backup database using VB
 Originally Posted by si_the_geek
In this case, it means that you will probably not be able to copy the file while your program is running
Copy the file or back up the database in any (practical) way. The database must be closed to back it up, so all forms that have controls bound to the database have to be unloaded first. And that makes for a very messy program.
Just one more reason to never use databound controls.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
May 26th, 2007, 07:14 AM
#14
New Member
Re: backup database using VB
 Originally Posted by Hack
Just bare in mind that the database MUST be closed before you can copy it.
hi,
i have the same prob i can copy the file but i need the code to close the connection can you help me?
thanks
-
May 26th, 2007, 09:45 AM
#15
Re: backup database using VB
Welcome to VBForums 
How you close it depends entirely on your code to declare (Dim) and open it - if you show us what you have, we can tell you what to do.
Note that if any other program has a connection open, you will not be able to force that connection to close.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|