Again I see people struggle to connect to Access database in forum so here is one solution.
This short article extract the key part of https://msdn.microsoft.com/en-us/library/ms971485.aspx to show you how to connect to MS Access database.
The 2 important things to watch out if you want to access to access to MS Access database.
1. You need to have Microsoft.Jet.Oledb.4.0 or newer in your machine (you will have it if you have Visual Studio 2008 or newer in your machine by right).
2. If you are running it as Web Application you might need to set the application pool to Enable 32-bit https://chanmingman.wordpress.com/2015/04/13/microsoft-jet-oledb-4-0-provider-is-not-registered-on-the-local-machine/.
The key part of the code is
private void ReadRecords()
OleDbConnection conn = null;
OleDbDataReader reader = null;
conn = new OleDbConnection(
@”Provider=Microsoft.Jet.OLEDB.4.0; “ +
@”Data Source=” + Server.MapPath(“Pets/Pets.mdb”));
OleDbCommand cmd =
new OleDbCommand(“Select * FROM PetTable”, conn);
reader = cmd.ExecuteReader();
datagrid.DataSource = reader;
if (reader != null) reader.Close();
if (conn != null) conn.Close();