Hi all ...
Iam looking for a code on how to backup a database using VB.İt's urgent.![]()
Hi all ...
Iam looking for a code on how to backup a database using VB.İt's urgent.![]()
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.
http://ganeshmoorthymc.com
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.
Please use [Code]your code goes in here[/Code] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.
Creating A Wizard In VB.NET
Paging A Recordset
What is wrong with using On Error Resume Next
Good Article: Language Enhancements In Visual Basic 2010
Upgrading VB6 Code To VB.NET
Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked
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.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
Some Informative Links: [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
[ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]
MS MVP 2006, 2007, 2008
I am using Access.but actually ı need the code.ı know ı have to take a backup but how?ı need the code.Originally Posted by ganeshmoorthy
![]()
ganeshmoorthy already told you how.Just bare in mind that the database MUST be closed before you can copy it.Originally Posted by ganeshmoorthy
Please use [Code]your code goes in here[/Code] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.
Creating A Wizard In VB.NET
Paging A Recordset
What is wrong with using On Error Resume Next
Good Article: Language Enhancements In Visual Basic 2010
Upgrading VB6 Code To VB.NET
Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked
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.
http://ganeshmoorthymc.com
what is cn?is it the name of the database?Originally Posted by ganeshmoorthy
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
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!
(2007, 2008, 2009, 2010, 2011, 2012) . . . . . . . . Hitchhiker's Guide to Getting Help at VBForums
Classic VB FAQs (updated Oct 2010) ...Database Development FAQs/Tutorials (updated May 2011)
(includes fixing common VB errors) .......... (includes fixing common DB related errors, and [Classic VB] ADO tutorial /further steps, and [VB.Net] ADO.Net Tutorial).
Tutorial: How to automate Excel from VB6 (or VB5/VBA) .. SQL 'Select' statement formatter/checker .. Convert colour number to colour name .. FlexGrid: fill from recordset .. FlexGrid: AutoSize columns .. DB Reserved Words checker
Connection strings .. MDAC/Jet/ACE downloads .. SQL Server downloads .. MZTools (free upgrade for the VB6/VBA Editor)
I have written the code :Originally Posted by si_the_geek
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
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
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.
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? ....Originally Posted by guncebertug
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"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.ı 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?
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.
(2007, 2008, 2009, 2010, 2011, 2012) . . . . . . . . Hitchhiker's Guide to Getting Help at VBForums
Classic VB FAQs (updated Oct 2010) ...Database Development FAQs/Tutorials (updated May 2011)
(includes fixing common VB errors) .......... (includes fixing common DB related errors, and [Classic VB] ADO tutorial /further steps, and [VB.Net] ADO.Net Tutorial).
Tutorial: How to automate Excel from VB6 (or VB5/VBA) .. SQL 'Select' statement formatter/checker .. Convert colour number to colour name .. FlexGrid: fill from recordset .. FlexGrid: AutoSize columns .. DB Reserved Words checker
Connection strings .. MDAC/Jet/ACE downloads .. SQL Server downloads .. MZTools (free upgrade for the VB6/VBA Editor)
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.Originally Posted by si_the_geek
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
hi,Originally Posted by Hack
i have the same prob i can copy the file but i need the code to close the connection can you help me?
thanks
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.
(2007, 2008, 2009, 2010, 2011, 2012) . . . . . . . . Hitchhiker's Guide to Getting Help at VBForums
Classic VB FAQs (updated Oct 2010) ...Database Development FAQs/Tutorials (updated May 2011)
(includes fixing common VB errors) .......... (includes fixing common DB related errors, and [Classic VB] ADO tutorial /further steps, and [VB.Net] ADO.Net Tutorial).
Tutorial: How to automate Excel from VB6 (or VB5/VBA) .. SQL 'Select' statement formatter/checker .. Convert colour number to colour name .. FlexGrid: fill from recordset .. FlexGrid: AutoSize columns .. DB Reserved Words checker
Connection strings .. MDAC/Jet/ACE downloads .. SQL Server downloads .. MZTools (free upgrade for the VB6/VBA Editor)