• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 720
  • Last Modified:

How to modify MS Access database properties collection (not data!) from a C# program?

What is the best way to access Microsoft Access (sorry!) Database object's properties (like in CurrenrDB.Properties) from C# MSVS 2010 please?

(Not essential: In fact I want to get rid of *Replication* in a few dozen databases "on demand". Replication is not in use for a few years, and it was OK for MS Access prior to 2013. Access 2013 rejects databases with this feature.)
  • 3
1 Solution
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You generally use DAO to do this. I don't have C# code for that, but from VBA:

Dim dbs As DAO.Database
Set dbs = OpenDatabase("path to db")

Dim prp As DAO.Property

For each prp in dbs.Properties
  Debug.Print prp.Name

I'm not sure exactly how you'd go about removing replication, however. Might be simplest to just create a new, blank database and import all of the Access objects there. You can do that with DAO as well.
midfdeAuthor Commented:
Thanks, great!
But I am expecting an answer to my question, in C#, not VBA please.
midfdeAuthor Commented:
using System.Text;
using System.Threading.Tasks;
using System.Data.OleDb;
using Microsoft.Office.Interop.Access;
using Microsoft.Office.Interop.Access.Dao;
namespace testPiaCs{
    class Program{
        static void Main( string[] args){
            Application app = new Application ();
            app.Visible = false;
            app.OpenCurrentDatabase( @"c:\1\1.accdb");
            Database db = app.CurrentDb();

Open in new window

midfdeAuthor Commented:
I expected more gracefull solution, without unnecessary Application Object.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now