Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Microsoft Access database in C# programmatically?

Tags:

How do you create a Microsoft Access database file in C# if it does not exist yet?

like image 649
LEMUEL ADANE Avatar asked Jan 24 '11 04:01

LEMUEL ADANE


People also ask

Can I use C# in Access?

A developer can work with a Microsoft Access database from Visual C# 2005 or Visual C# . NET by using two separate technologies: Automation and Microsoft ADO.NET. ADO.NET is the preferred technology if you want to work with data objects, such as tables and queries in an Access database.

What coding language is used in Access?

Access uses Visual Basic for Applications (VBA) as its development language.


1 Answers

The simplest answer is to embed an empty .mdb / .accdb file in your program and write it out to disk.

The correct answer is to use COM Interop with the ADOX library:

var cat = new ADOX.Catalog()
cat.Create(connectionString);

Remember to generate your connection strings using OleDbConnectionStringBuilder.

like image 137
SLaks Avatar answered Sep 23 '22 12:09

SLaks