Connecting MS Access Database in C#

Let’s how we can connect to an MS Access database (accdb) in C#.

String _database_path = "path/to/database/file";
String _conn_str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" 
             + _database_path + 
             ";Persist Security Info=False";
 
//connect
OleDbConnection _connection = new OleDbConnection(_conn_str);
_connection.Open();
 
//disconnect
_connection.Close();
Categories: C# Tags: , , , , ,
%d bloggers like this: