 |
|
|
 |
|
|
Hey ur code is GR8.
But while running i am getting an error saying. "Exception has been thrown by the target of an invocation."
Plz help
|
| Sign In·View Thread·PermaLink | 1.22/5 (6 votes) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
Be careful when using this CompactDatabase API. I have found that sometimes CompactDatabase will trash a perfectly good Access Database file. Before you call CompactDatabase, you should make a backup copy of the file just in case the processed database file is damaged by the CompactDatabase call. An alternative to using CompactDatabase is jetcomp.exe which is available from Microsoft here http://support.microsoft.com/kb/295334[^]. My experience has shown that jetcomp.exe is much safer to use than CompactDatabase. This of course is not as clean or easy as using CompactDatabase since you have to launch the jetcomp.exe with command line parameters to get it to do what you want.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
How to set the adodb.connection.OpenSchema parameters in c#?
ADODB.Recordset OpenSchema(ADODB.SchemaEnum Schema, object Restrictions, object SchemaID)
I can't set the right parameters with "object Restrictions & object SchemaID"
Thanks!
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
I get an exception on this line: objJRO.GetType().InvokeMember("CompactDatabase", System.Reflection.BindingFlags.InvokeMethod, null, objJRO, oParams);
It says: "Exception has been thrown by the target of an invocation"
and the inner exception is: "You attempted to open a database that is already opened exclusively by user 'Admin' on machine . Try again when the database is available."
But I checked and the DB is closed.
Can any one help?...
Thanks, Roee.
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
|
Hi,
I was wondering why not giving the source and destination the same database connection to avoid the harassing 'Delete' issue. After a few tries discovered that it was not possible with both OLE DB and ADO. So I googled a bit and found a different but more compact way usin ODBC:
[System.Runtime.InteropServices.DllImport("ODBCCP32.dll")] private static extern bool SQLConfigDataSource(IntPtr parent, int request, string driver, string attributes); private const int ODBC_ADD_DSN = 1;
public static bool Compact(string mdbFileName) { string cmd = string.Format("COMPACT_DB={0} {0}\0\0", mdbFileName); return SQLConfigDataSource((IntPtr)0, ODBC_ADD_DSN, "Microsoft Access Driver (*.MDB)", cmd); }
public static bool Compact(string mdbFileName, string password) { string cmd = string.Format("COMPACT_DB={0} {0}\0PWD={1}\0\0", mdbFileName, password); return SQLConfigDataSource((IntPtr)0, ODBC_ADD_DSN, "Microsoft Access Driver (*.MDB)", cmd); }
NOTE: It works with my current OS configuration but from the MSDN Library I also found this old article: BUG: Database Compaction with SQLConfigDataSource Fails when Access Database is Password Protected
|
| Sign In·View Thread·PermaLink | 3.00/5 (2 votes) |
|
|
|
 |
|
|
the old mdb has a password... but after compacting and repaired the password has gone...
why?
JoeAdrianBlack
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
joeblack wrote: the old mdb has a password... but after compacting and repaired the password has gone...
Same for me,
does anyone have a clue how to set an access password programmatically?
THX
Sebastian Lorenz
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
you won't believe how easy it is...
Just set the OLEDB:Database Password=yourpass in the oParams array, and there you are!
Hope this helps you out, it did for me.
Sebastian Lorenz
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Hi,
thanks for this example 
I just have a little question : is it REALLY safe to use this code, I mean, in production environment ? Because it delete the original file... maybe there are some RARE situations where the database could be completely swept ?
|
| Sign In·View Thread·PermaLink | 1.20/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
Hi I need to repair access file in c++ program, so I should write this function in c++. Because I do not know c# so someone help me with this function written in c++. Tha nks.
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
If the JRO is not registered .... it will not work....
but you can modify the code to automatically register the com-object
Type typJRO=Type.GetTypeFromProgID("JRO.JetEngine"); if (typJRO==null) { //phps. msjro is not registered string strMsjrodll=Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"),@"Common Files\System\ado\msjro.dll"); if (File.Exists(strMsjrodll)) { //start a process to register the dll Process procRegisterMsjro=Process.Start("regsvr32.exe",string.Concat("/s \"",strMsjrodll,"\"")); procRegisterMsjro.WaitForExit(); typJRO=Type.GetTypeFromProgID("JRO.JetEngine"); } }
if (typJRO==null) { throw new InvalidOperationException("JRO.JetEngine can not be created... please check if it is installed"); }
//create an inctance of a Jet Replication Object object objJRO = Activator.CreateInstance(typJRO);
|
| Sign In·View Thread·PermaLink | 3.50/5 (2 votes) |
|
|
|
 |
|
|
Very helpful article, but when I run my program I get an exception. The error message says "Format of the initialization string does not conform to the OLE DB specification". I have no idea why it is not working. I have tried messing around with the connection string but nothing seems to help. Most of my code is exactly how you have it: object[] oParams; object objJRO = Activator.CreateInstance(Type.GetTypeFromProgID("JRO.JetEngine"));
string conn="C:\\"; oParams = new object[] {conn, "Provider=Microsoft.Jet.OLEDB.4.0;Data" + "Source=C:\\tempdb.mdb;Jet OLEDB:Engine Type=5"};
\\ This is where it is crashing on me objJRO.GetType().InvokeMember("CompactDatabase", System.Reflection.BindingFlags.InvokeMethod,null,objJRO,oParams); Thank you so much, Ben
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Your code was great. I made what I think are some enhancements to the cod.
Thanks!!!
Public Sub CompactAccessDB(ByVal mdbToCompact As String)
'Boilerplate for connection strings Const JET_CONNECTION_STRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data" + " Source={0};Jet OLEDB:Engine Type=5"
Dim objJRO As Object Dim tempFile As String Dim oParams As Object()
Try
'Get temp filename for compacted MDB 'HACK: To prevent "Database Already Exists" error we add "FOO" to the end of system generated filename. The CompactDB fuction will then create a new compcated DB with the system generateed name with "FOO" appended. Function Path.GetTempFileName() gets filename AND creates file which causes a problem here tempFile = Path.GetTempFileName() & "FOO"
'Setup object arrary to hold connection strings for CompactDatabase meathod on JRO.JetEngine object oParams = New Object() {String.Format(JET_CONNECTION_STRING, mdbToCompact), String.Format(JET_CONNECTION_STRING, tempFile)}
'Get instanct of JRO.JetEngine object which will do the actual work of compacted the MDB objJRO = Activator.CreateInstance(Type.GetTypeFromProgID("JRO.JetEngine"))
'Compact the database... objJRO.GetType.InvokeMember("CompactDatabase", System.Reflection.BindingFlags.InvokeMethod, Nothing, objJRO, oParams)
'Delete the old database System.IO.File.Delete(mdbToCompact)
'Replace it with the new compacted mdb System.IO.File.Move(tempFile, mdbToCompact)
Catch ex As Exception 'Just send the exception up to the caller Throw ex Finally 'Release memory System.Runtime.InteropServices.Marshal.ReleaseComObject(objJRO) objJRO = Nothing
End Try
End Sub
"I don't know were I'm goin' but I'm on the way" - Me
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
 |
 | Thanks |  | Anonymous | 9:37 31 Jan '05 |
|
|
 |
|
|
Hi, I'm new to c# but can't see how exactly to call the CompactAccessDB method and pass in the parameters. How do I run this code for a database located at c:\compact.mdb
Thanks
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
if the initial dataase has a password in the connection string, the replacement database doesnt have the database... do you know how to set a password programaticly?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hmmm, can’t actually believe I wrote that!!! Must have been real late… what I mean to illustrate is that the method you uses would actually remove the password from the database.. do you know how to set it programmatically?
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |