Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access 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 November 6th, 2003, 03:50 PM
Registered User
Join Date: Nov 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can't connect to access database using C# code...


I am a beginning programmer. Problem:

I am trying to open a Microsoft ACCESS database using OLEDB. The exception raised when trying to open the .MDB is "database is not registered on this machine"

Here is the code I am using:

using System;
using System.Data;
using System.Data.OleDB;

namespace Wrox.BeginningCSharpDatabases.Chapter05
  class Connection_OleDB {
    static void Main()
      OleDBConnection thisConnection = new OleDBConnection(
                               @"Provider=Microsoft.Jet.OLEDB.4.0;" +
                                @"Data Source=c:\Northwind.MDB"

    // Open connection
    }//end Main

No access databases will open. I am able to open SQL databases (by changing appropriate references)just fine.

How do you register an Access database on the local (or) remote machine???

Thanks so much in advance,

Old November 8th, 2003, 02:08 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts

Odd exception. Your code shouldn't even compile. Remember, C# is case sensitive,
so OleDB and OleDb are not the same identifier. Also, your connection string
needs to be closed with a closing paren and semi-colon. The code below should
open a connection for you, provided you are running a Windows application. Things
are a bit different with ASP.NET Web applications, because you need to take user
authentication and authorization into account, usually by impersonating your NT
authentication account.

using System;
using System.Data;
using System.Data.OleDb;

namespace ConsoleApplication1
   class Class1
      static void Main(string[] args)
         OleDbConnection thisConnection = new OleDbConnection(
                  @"Provider=Microsoft.Jet.OLEDB.4.0;" +
                  @"Data Source=c:\Northwind.MDB");

    // Open connection




Similar Threads
Thread Thread Starter Forum Replies Last Post
Connect to Remote SQL database via Code jscammell VB How-To 1 May 20th, 2007 12:00 AM
How to connect to a access database with password? yuetqu VB.NET 2002/2003 Basics 1 September 10th, 2006 01:56 PM
HOW TO programatically connect to Access Database Deepa7476 Visual Basic 2005 Basics 4 May 23rd, 2006 09:12 AM
how vb.net connect access database abbee99 ADO.NET 1 April 29th, 2005 04:21 AM
How to connect to an MS Access database? petercahyadi Java Databases 3 February 22nd, 2005 07:28 PM

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