2

I'm trying to create a database in C# using a Windows Forms App in Visual Studio 2017. No matter what I try, I'm getting the same error. I know everyone says it's an x64 thing, but I've set my platform to x86.

Here's the error

System.Runtime.InteropServices.COMException
  HResult=0x80040154
  Message=Class not registered
  Source=Ex3
  StackTrace:
   at ADOX._Catalog.Create(String ConnectString)
   at Ex3.FmMenu.FmMenu_Load(Object sender, EventArgs e) in C:\Users\benjo\Apps\CS\CSharp\Ex3\Ex3\FmMenu.cs:line 26
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

And here's the code I'm trying to get to work, the error occurs on the first line

new ADOX.Catalog().Create(Program.ConnString);
OleDbConnection Conn = new OleDbConnection(Program.ConnString);
Conn.Open();
OleDbCommand Cmd = new OleDbCommand();
Cmd.Connection = Conn;

Everyone says I should try setting my program to run in 32-bit mode, but that hasn't changed anything

Kzryzstof
  • 7,688
  • 10
  • 61
  • 108
Ben
  • 394
  • 7
  • 13
  • Are you using ADOX just to create the database? Are you forced to use this outdated approach? What if you keep a blank database as base model and when you need to create the database you just copy the model to the appropriate folder with the appropriate name? – Steve Apr 26 '18 at 16:56
  • I'm a student, I could do that (and probably will), but my assignment requires me to show an understanding of how to create a database in C#. I'd still like a solution to this problem, thanks – Ben Apr 26 '18 at 18:46
  • "I've set my platform to x86". Too many programmers get this wrong, they change the solution platform. Irrelevant to C#, it is the Project > Properties > Build tab settings that matter. – Hans Passant Apr 26 '18 at 20:51
  • Visual Studio includes LocalDb, a SQL Server variant for developers. If all you want is to create a tiny database that would be the way to go. – ZiggZagg Apr 26 '18 at 21:29
  • I've set the target to x86 in the build tap of project properties, still getting the same error – Ben Apr 27 '18 at 06:46

0 Answers0