Hi Friends,
I am not able to connect to local system Msaccess database with .mdb file with Oledb and Odbc connection.
The database have password.I tried with different solution but getting system.data.oledb is not supported on this platform error.
string connectionString = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\DB_BKUP\RESTSALES.mdb;Jet OLEDB:Database Password=Touchpoint;");
conn.Open();
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
try
{
connection.Open();
// Execute database operations using OleDbCommand
// For example, select data from a table
string query = "SELECT * FROM TRANSACTIONDETAILS";
using (OleDbCommand command = new OleDbCommand(query, connection))
{
using (OleDbDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
// Access data using reader
Console.WriteLine(reader["ColumnName"].ToString());
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
Please tell me how to connect to the local access db file from windows forms or WPF application

Jayraj ChhayaRank #304 · 8.2K reputationPosted Feb 29, 2024, 6:18 AM EST
Hi prasanna p,
To connect to a local Access database (.mdb file) from a Windows Forms or WPF application using OLEDB or ODBC, you need to ensure that you have the necessary drivers installed on your system.
If you are encountering the "System.Data.OleDb is not supported on this platform" error, it could be due to missing or incompatible drivers. Here are a few steps you can follow to resolve this issue:
Install the Microsoft Access Database Engine:
Update your connection string:
string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Path\To\Your\Database.mdb;Jet OLEDB:Database Password=YourPassword;";Check the target platform of your application:
Verify the reference to System.Data.OleDb:
System.Data.OleDbassembly. You can check this in the References section of your project.Once you have followed these steps, you should be able to connect to your local Access database using OLEDB or ODBC in your Windows Forms or WPF application.
Please note that the code snippet you provided uses both OLEDB and ODBC connections. It is recommended to choose one connection type (either OLEDB or ODBC) and modify your code accordingly.
prasanna pRank #3,234 · 443 reputationPosted Feb 29, 2024, 7:17 AM EST
hi Jayraj, I followed all the steps, getting same error System.Data.OleDb is not supported on this platform
Anil SharmaRank #4,829 · 323 reputationPosted Mar 5, 2024, 8:11 AM EST
One of the Reason is System.Data.OleDb is not supported in .NET Core