How can I create a empty .mdb file? I'm using ADO.NET and C#. Thanks!
+3
A:
Copy a pre-existing .mdb file is the best way.
The same is true for most of the other filebased database formats that ADO.NET can connect to, such as Excel files. Since a file based database system is using the filesystem as it's host and API for communication with the outside world (as opposed to say MSSQL which communicates using TCP-IP), it quite natural to use System.IO for actions that in say MS-SQL would be done with T-SQL or system stored procedures or a data specific API that targets thoses (say SMO in SQL server's case).
COPY model.mdb newdb.mdb
is the create DB command
DEL newdb.mdb is the drop
DB command, etc.
MatthewMartin
2008-12-06 19:08:17
+1
A:
I don't think there is a ".NET native" way to do it, but you still can wrap ADOX:
using ADOX; // add a COM reference to "Microsoft ADO Ext. x.x for DDL and Security"
static void CreateMdb(string fileNameWithPath)
{
ADOX.Catalog cat = new ADOX.Catalog();
string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Engine Type=5";
cat.Create(String.Format(connstr, fileNameWithPath));
cat = null;
}
Tomalak
2008-12-06 19:24:10
I then get a Class Not Registered error on the cat.Create
Malfist
2008-12-06 19:37:31
Are you on 64 bit? From what I find in Google this may be causing it. (see: http://www.c-sharpcorner.com/Forums/ShowMessages.aspx?ThreadID=47427)
Tomalak
2008-12-06 22:25:10