Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > Copying Database


Reply
 
Thread Tools Display Modes
  #1  
Old 03-26-2004, 03:21 AM
iLLiCiT iLLiCiT is offline
Freshman
 
Join Date: Dec 2003
Location: Paradise
Posts: 27
Default Copying Database


Hi,

I want to copy a database, say "C:\Data\stuff.mdb" to "C:\Data\stuff2.mdb". However, I need to copy the database when it is open. I.e. my program uses the database, and then I need to copy it.

Is this possible? If so, how do I do it?

I have tried fileCopy but it won't work because the file can't be open. I also tried DBEngine.CompactDatabase but that has the same permission problems.

Any help would be appreciated,

Craig
__________________
"In the quiet words of the Virgin Mary...'"Come again?"'"
Reply With Quote
  #2  
Old 03-26-2004, 03:30 AM
RedLeader's Avatar
RedLeader RedLeader is offline
Centurion
 
Join Date: Jan 2004
Location: Bulgaria
Posts: 121
Default

Code:
Dim MyConn As ADODB.Connection
Set MyConn = New ADODB.Connection
MyConn.ConnectionString = "your connection string "
MyConn.Open

MyConn.Execute ("INSERT INTO stuff2(fields1,fields2,...)SELECT fields1,fields2,....  from stuff  ")
MyConn.Close
Reply With Quote
  #3  
Old 03-26-2004, 03:38 AM
iLLiCiT iLLiCiT is offline
Freshman
 
Join Date: Dec 2003
Location: Paradise
Posts: 27
Default

Thank you for your quick reply.

Excuse me here, but does your code not copy fields within the same .mdb file? If I am wrong then I appologise.

Just to clear things up, I explicitly need two separate .mdb files, so that I can send one by FTP, then delete the temporary .mdb file.

BRgrds
__________________
"In the quiet words of the Virgin Mary...'"Come again?"'"
Reply With Quote
  #4  
Old 03-30-2004, 02:55 PM
XtremeCosmos XtremeCosmos is offline
Newcomer
 
Join Date: Mar 2004
Location: United Kingdom
Posts: 22
Default

Have you tried killing the lock file? Not sure if it will work.
Kill YourDatabase.ldb
Reply With Quote
  #5  
Old 03-30-2004, 03:04 PM
MKoslof's Avatar
MKoslof MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

No, the file must be closed. You can't copy an Access mdb while it is open. Through VB, you need to close your ADO or DAO connection to the database file, then attempt to copy it.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #6  
Old 03-30-2004, 06:13 PM
wengwashere's Avatar
wengwashere wengwashere is offline
Contributor
 
Join Date: Apr 2002
Location: brgy Ginebra
Posts: 449
Default

how about doing a back up of it?
Reply With Quote
  #7  
Old 03-31-2004, 06:34 AM
MKoslof's Avatar
MKoslof MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

No, same problem. You need to make sure that any DAO or ADO connection to your mdb file CLOSED before trying to copy your database, running a compact and repair, or any other type of maintance.

And, instead of using a standard fileCopy command, I would use the CopyFile API method. It is quick and returns an integer value so you know whether or not it was successful.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Database (Data Control) Error vbtester Database and Reporting 3 10-01-2003 05:49 PM
Backup database destress Database and Reporting 3 07-14-2003 01:04 AM
copying a table from a database to another JohnDoe Word, PowerPoint, Outlook, and Other Office Products 2 08-01-2002 10:36 AM
Creating, and copying data from a form into a database cmsdcarr Database and Reporting 1 06-10-2002 12:24 PM
Unrecognized Database Format foongkim Database and Reporting 4 01-12-2001 11:10 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->