By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,471 Members | 2,277 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,471 IT Pros & Developers. It's quick & easy.

How do I compress/repair access database from code?

P: n/a
Subject says it all. I am writing in C++/OLEDB and want to compress + repair
from my program, what do I have to do?

Thanks,

RDeW
Nov 13 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The correct term is Compact & Repair. Use the DAO
"DBEngine.CompactDatabase" method.

This example is in VBA & from the Access VBA help file. Perhaps you can
translate to C++/OLEDb.

Sub CompactDatabaseX()

Dim dbsNorthwind As Database

Set dbsNorthwind = OpenDatabase("Northwind.mdb")

' Show the properties of the original database.
With dbsNorthwind
Debug.Print .Name & ", version " & .Version
Debug.Print " CollatingOrder = " & .CollatingOrder
.Close
End With

' Make sure there isn't already a file with the
' name of the compacted database.
If Dir("NwindKorean.mdb") <> "" Then _
Kill "NwindKorean.mdb"

' This statement creates a compact version of the
' Northwind database that uses a Korean language
' collating order.
DBEngine.CompactDatabase "Northwind.mdb", _
"NwindKorean.mdb", dbLangKorean

Set dbsNorthwind = OpenDatabase("NwindKorean.mdb")

' Show the properties of the compacted database.
With dbsNorthwind
Debug.Print .Name & ", version " & .Version
Debug.Print " CollatingOrder = " & .CollatingOrder
.Close
End With

End Sub

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQXrcFYechKqOuFEgEQLYUwCgzdV2bvnf+cgWDEHuDrF0xg LmXeIAn3af
k6AXGDumADY4P43Oy7vx7b59
=o5LA
-----END PGP SIGNATURE-----
Riley DeWiley wrote:
Subject says it all. I am writing in C++/OLEDB and want to compress + repair
from my program, what do I have to do?


Nov 13 '05 #2

P: n/a
Neither C++ nor OLEDB has the innate ability to compact & repair, so you'll
need a reference to another library.
If your users will have Access installed on their machines, you can use the
DAO solution posted.
However, to my knowledge the DAO library itself is not freely distributable.
It's my understanding that the JRO library is both freely distributable and
smaller than the DAO library.
What I don't know is how well it works from C++ -
but give it a try!
"Riley DeWiley" <ri***********@gmail.com> wrote in message
news:10*************@corp.supernews.com...
Subject says it all. I am writing in C++/OLEDB and want to compress + repair from my program, what do I have to do?

Thanks,

RDeW

Nov 13 '05 #3

P: n/a
Hi:

I am trying to use the code posted by MGFoster on this subject, but when I try and use it
I get an error "user-defined type not defined" on the first line ( Dim dbsNorthwind As
Database). I have modified other lines to refer to my database, and am a bit perplexed as
to why this is happening.

Can someone point me in the right direction please.

John Baker
Nov 13 '05 #4

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Access versions 2000, and higher, require a Reference to the DAO library
(VBA module, main menu: Tools > References). To Dim the variable, do it
this way:

Dim dbsNorthwind As DAO.Database

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQX1HToechKqOuFEgEQI98gCfd6wYsQ/GaTswdwfJQgyP1e91P70AoNtm
i8kKPNEjrjpz+89OnlSAXktn
=XtxV
-----END PGP SIGNATURE-----
John Baker wrote:
Hi:

I am trying to use the code posted by MGFoster on this subject, but when I try and use it
I get an error "user-defined type not defined" on the first line ( Dim dbsNorthwind As
Database). I have modified other lines to refer to my database, and am a bit perplexed as
to why this is happening.

Can someone point me in the right direction please.


Nov 13 '05 #5

P: n/a
I dimly recall seeing a way you could pass an SQL "query" to a Jet backend
to get it to compact ... I have a hard time believing this is not possible
with the standard libs, it is almost impossible to even run access without
compacting every now and again ..

"MacDermott" <ma********@nospam.com> wrote in message
news:lC*****************@newsread3.news.atl.earthl ink.net...
Neither C++ nor OLEDB has the innate ability to compact & repair, so you'll need a reference to another library.
If your users will have Access installed on their machines, you can use the DAO solution posted.
However, to my knowledge the DAO library itself is not freely distributable. It's my understanding that the JRO library is both freely distributable and smaller than the DAO library.
What I don't know is how well it works from C++ -
but give it a try!
"Riley DeWiley" <ri***********@gmail.com> wrote in message
news:10*************@corp.supernews.com...
Subject says it all. I am writing in C++/OLEDB and want to compress +

repair
from my program, what do I have to do?

Thanks,

RDeW


Nov 13 '05 #6

P: n/a
Sorry, I don't think I've ever seen such SQL -
which of course doesn't mean it doesn't exist.
(Googling newsgroups can bring up a lot of treasures.)
I'm not sure what you mean by "the standard libs".
Not all the libraries which are part of a standard install of Access are
freely distributable.

Microsoft has a couple of articles on compacting using OLEDB:
http://support.microsoft.com/default...b;EN-US;230501
http://support.microsoft.com/kb/230496/EN-US/
using two different libraries (one of them JRO) from MDAC.

HTH
- Turtle
"Riley DeWiley" <ri***********@gmail.com> wrote in message
news:10*************@corp.supernews.com...
I dimly recall seeing a way you could pass an SQL "query" to a Jet backend
to get it to compact ... I have a hard time believing this is not possible
with the standard libs, it is almost impossible to even run access without
compacting every now and again ..

"MacDermott" <ma********@nospam.com> wrote in message
news:lC*****************@newsread3.news.atl.earthl ink.net...
Neither C++ nor OLEDB has the innate ability to compact & repair, so

you'll
need a reference to another library.
If your users will have Access installed on their machines, you can use

the
DAO solution posted.
However, to my knowledge the DAO library itself is not freely

distributable.
It's my understanding that the JRO library is both freely distributable

and
smaller than the DAO library.
What I don't know is how well it works from C++ -
but give it a try!
"Riley DeWiley" <ri***********@gmail.com> wrote in message
news:10*************@corp.supernews.com...
Subject says it all. I am writing in C++/OLEDB and want to compress +

repair
from my program, what do I have to do?

Thanks,

RDeW



Nov 13 '05 #7

P: n/a
Come to think of it, I did turn this up, thanks:

http://support.microsoft.com/kb/230496/EN-US/
Nov 13 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.