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
Anil SharmaPosted Mar 5, 2024, 1:11 PM
One of the Reason is System.Data.OleDb is not supported in .NET Core
prasanna pPosted Feb 29, 2024, 12:17 PM
hi Jayraj, I followed all the steps, getting same error System.Data.OleDb is not supported on this platform
Jayraj ChhayaPosted Feb 29, 2024, 11:18 AM
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:
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.