Click here to Skip to main content
15,910,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can any one help me in understanding the error raised on the InvokeMember method:

System.Reflection.TargetInvocationException - Exception has been thrown by the target of an invocation.
InnerException - Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done. {System.Runtime.InteropServices.COMException}
C#
//var conStr = GetConnectionString(strFileOutput, String.Empty);
var conStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Access 12.0;";
conStr += "Data Source=C:\\test.accdb;Persist Security Info=False;";

var catType = Type.GetTypeFromProgID("ADOX.Catalog");

object obj = Activator.CreateInstance(catType);

catType.InvokeMember("Create", BindingFlags.InvokeMethod, null, obj, new object[] { conStr });

OleDbConnection cnn = new OleDbConnection(conStr);

cnn.Open();
Posted

1 solution

Try this:

C#
using System;
 using ADOX;

 namespace ConsoleApplication1
 {
     class Class1
     {
         [STAThread]
         static void Main(string[] args)
         {
             ADOX.Catalog cat = new ADOX.Catalog();

             cat.Create("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\test.accdb;");

             Console.WriteLine("Database Created Successfully");

             cat = null;

         }
     }
 }


I would avoid the Activator and setting through reflection if you don't need to. I think the error you are getting is because it's trying to create a connection with a lot of properties set on a database that doesn't exist. You need to simplify your connection string, then when you want to open it you can use the rest of the properties.
 
Share this answer
 
v2
Comments
Sangeeth Mohan 24-Jun-13 11:02am    
The issue on my code was just on the Connection String. It worked when changed it appropriately.

But your answer simplified the code. I am using this new code in my project.

Thanks a lot, Ron.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900