Connecting to a Microsoft Access Database

 Use the OLE DB .NET data provider.

 The solution creates and opens a connection to a Microsoft Access database using the OLE DB .NET data provider. Information about the connection is displayed.

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

namespace ConnectAccessDatabase
    class Program
      static void Main(string[] args)
          string oledbConnectString =
            "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
            @"C:\Documents and Settings\bill\My Documents\" +
           "Northwind 2007.accdb;";
         using (OleDbConnection connection =new OleDbConnection
          connection.Open(  );

     // Output some connection and database information.
        Console.WriteLine("Connection State:{0}",connection.State);
        Console.WriteLine("OLE DB Provider:{0}",connection.Provider);
        Console.WriteLine("Server Version:{0}",connection.ServerVersion);
        Console.WriteLine("\nPress any key to continue.");
        Console.ReadKey(  );

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: