Wrox Programmer Forums
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 25th, 2007, 01:20 AM
Authorized User
 
Join Date: May 2007
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to MathLearner
Default compacting database pblm

hi all:)
     my coding works correctly for compacting. but after opening any report (ie crystal report)it doesnt works.
           here the errror mentioned is
 error no 3049
         cannot open database(filename).it may not be a databse that your application recongnizes or file may corrupt.
  here is the code

         Public Sub Compact_DB(DBF_Path)
On Error GoTo disp_err
Dim FSO As New FileSystemObject

Dim tmp_file1
Dim tmp_file2
' First Close all the Databases

If Dir(App.Path & "\PA_COMPACT.00~") <> "" Then
   FSO.DeleteFile App.Path & "\PA_COMPACT.00~"
End If

If Dir(App.Path & "\PA_BK.BK") <> "" Then
   FSO.CopyFile App.Path & "\PA_BK.BK", App.Path & "\PA_BK.BK1", True
End If

If Dir(App.Path & "\PA_COMPACT.00~") <> "" Then
   FSO.DeleteFile App.Path & "\PA_COMPACT.00~"
End If
If Dir(App.Path & "\PAT_COMPACT.00~") <> "" Then
   FSO.DeleteFile App.Path & "\PAT_COMPACT.00~"
End If
tmp_file1 = App.Path & "\" & "PA_COMPACT" & ".00~"
tmp_file2 = App.Path & "\" & "PAT_COMPACT" & ".00~"

If Dir(DBF_Path) = "" Then
   tmp = MsgBox("The Database file at location : " & DBF_Path & " Not Found!!!" & vbLf & "Check the Server Status or Drive Mappings!!!", vbCritical, "Database Not Found!!!")
   Exit Sub
Else

   ''' Delete all the temporaty tables in the database

    If moConn.State = 1 Then
        moConn.Close
    End If

' moConn.Close
' moConn.Open

   DBEngine.CompactDatabase DBF_Path, tmp_file1
   'DBEngine.CompactDatabase DBF_Path1, tmp_file1
   ''Rename the Database to Original Name
   Rename_File tmp_file1, DBF_Path
   DoEvents
   tmp = MsgBox("Compacted Successfully.", vbExclamation, "Compact")
End If

Exit Sub
disp_err:
    tmp = MsgBox(Err.Description, vbCritical, "Compact : " & Err.Number)
    Exit Sub
End Sub

Public Function Rename_File(Old_Name, New_Name) As Boolean
' Rename the file. If new name already exists it deletes it.
On Error GoTo disp_err
Dim OldName, NewName
If Dir(New_Name) <> "" Then
   Kill New_Name
End If
OldName = Old_Name: NewName = New_Name ' Define file names.
DoEvents
Name OldName As NewName ' Rename file.
Rename_File = True
Exit Function
disp_err:
    tmp = MsgBox(Err.Description, vbCritical, "Rename : " & Err.Number)
    Rename_File = False
    Resume Next
End Function

help us..


 
Old September 25th, 2007, 07:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. can you explain a little better when the error occurs? and where it happens?? it's not clear is the error is after compacting of before compacting or if you are trying to open a report after compacting...
and can you post the offending line??

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old September 26th, 2007, 05:11 AM
Authorized User
 
Join Date: May 2007
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to MathLearner
Default

hi sir
      iam not able to compact the database after opening a report.
here the errror mentioned is
 error no 3049
         cannot open database(filename).it may not be a databse that your application recongnizes or file may corrupt.
pls help us..


 
Old September 26th, 2007, 07:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

so.. you have your database still openend, maybe you are not closing it after opening the report?

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old September 26th, 2007, 07:45 AM
Authorized User
 
Join Date: May 2007
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to MathLearner
Default

hi sir
     Thank u for ur kind response.how to close the database after opening the report through coding..giv me one example..
pls help us..



 
Old September 26th, 2007, 07:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

well.. that's depends on the report engine you are using and how are you opening the database.. is not a simple question ;)

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old September 27th, 2007, 06:34 AM
Authorized User
 
Join Date: May 2007
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to MathLearner
Default

hi sir
     Thank u for ur kind response. W

 
Old September 27th, 2007, 06:35 AM
Authorized User
 
Join Date: May 2007
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to MathLearner
Default

hi sir
     Thank u for ur kind response. We are using crystal reports 10.
How to close the database after opening the crystal reports through coding..giv me one example..



 
Old September 27th, 2007, 07:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

commmandobject.close?? that will close that object.. you will have to close any connection you opened so the database will close.. Still it could take a while since it really close, sometimes OS take time to flush caches and things like that..
Also could be that you are not closing the report and still it has a connection to the database.. you will have to check your code for this... there is no easy or direct answer for your problem...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Compacting database Scootterp Access VBA 5 August 9th, 2006 09:33 AM
Compacting Access Database problem imaley SQL Language 1 April 23rd, 2004 11:28 AM
Compacting Access Database from code imaley Access 6 March 31st, 2004 05:33 PM
Automatically Compacting a Database nanohurtz Access 2 March 22nd, 2004 10:25 AM
Compacting a large database takabyte Classic ASP Databases 1 February 5th, 2004 12:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.