Linux下MonoDevelop创建OleDbConnection遇System.NotImplementedException报错
System.NotImplementedException (OleDb is not implemented.) in MonoDevelop (Linux) Hey there! Let's break down why this error is popping up on your Linux MonoDevelop setup, even though your code runs fine in Visual Studio on Windows.
Why You're Seeing This Error
OleDb is a Windows-exclusive technology—it depends heavily on Windows-specific COM components and system libraries that don't exist in Linux environments.
When you run your code in Visual Studio (Windows), you’re using Microsoft’s official .NET implementation, which includes full support for OleDb. But on Linux, Mono (the open-source .NET alternative) doesn’t have a working implementation of OleDb. That’s exactly why you get the NotImplementedException when trying to create an OleDbConnection.
How to Fix It
You’ll need to replace OleDb with a cross-platform database driver that works on both Windows and Linux. Here are your best options based on the database you’re using:
1. If connecting to SQL Server
Use Microsoft.Data.SqlClient, Microsoft’s official cross-platform driver for SQL Server. First install the package via NuGet in MonoDevelop, then update your code like this:
using System; using Microsoft.Data.SqlClient; namespace Tests { class MainClass { public static void Main(string[] args) { // Replace with your actual SQL Server connection string string connString = "Server=your_server;Database=your_db;User Id=your_user;Password=your_pass;"; using (SqlConnection connection = new SqlConnection(connString)) { try { connection.Open(); Console.WriteLine("Connection successful!"); } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } } } } }
2. If using SQLite (lightweight file-based database)
SQLite is perfect for cross-platform apps, and works with either Mono.Data.Sqlite (built into Mono) or Microsoft.Data.Sqlite (official Microsoft package):
using System; using Mono.Data.Sqlite; namespace Tests { class MainClass { public static void Main(string[] args) { // Connection string for a local SQLite database file string connString = "Data Source=my_local_db.db;Version=3;"; using (SqliteConnection connection = new SqliteConnection(connString)) { try { connection.Open(); Console.WriteLine("SQLite connection successful!"); } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } } } } }
3. For other databases (MySQL, PostgreSQL, etc.)
- MySQL: Use
MySqlConnector, a widely used cross-platform driver - PostgreSQL: Use
Npgsql, the official .NET driver for PostgreSQL
Both are available via NuGet and work seamlessly on Linux and Windows.
Key Takeaway
OleDb won’t work on Linux with Mono—you have to use a database driver built for cross-platform compatibility. All the options above will let you run your code on both Windows (Visual Studio) and Linux (MonoDevelop) without issues.
内容的提问来源于stack exchange,提问作者Oval

