Microsoft KB Archive/317867

= How to create a Microsoft Access database by using ADOX and Visual Basic .NET =

Article ID: 317867

Article Last Modified on 5/16/2007

-

APPLIES TO


 * Microsoft ADO.NET 1.1
 * Microsoft ADO.NET 1.0
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-



This article was previously published under Q317867



Caution ADO and ADO MD have not been fully tested in a Microsoft .NET Framework environment. They may cause intermittent issues, especially in service-based applications or in multithreaded applications. The techniques that are discussed in this article should only be used as a temporary measure during migration to ADO.NET. You should only use these techniques after you have conducted complete testing to make sure that there are no compatibility issues. Any issues that are caused by using ADO or ADO MD in this manner are unsupported. For more information, see the following article in the Microsoft Knowledge Base:

840667 You receive unexpected errors when using ADO and ADO MD in a .NET Framework application





For a Microsoft Visual C# .NET version of this article, see 317881.

IN THIS TASK
SUMMARY
 * Requirements
 * Steps to Build Example
 * Troubleshooting

REFERENCES



SUMMARY
Programmers may have to create databases programmatically, but neither ActiveX Data Objects (ADO) nor ADO.NET provides the means to create Microsoft Access databases. However, you can create Access databases by using the Microsoft Jet OLE DB Provider and Microsoft ADO Ext. 2.7 for DDL and Security (ADOX) with the COM Interop layer.

Requirements

 * Microsoft Visual Basic .NET
 * ADO Ext. 2.7 for DDL and Security (ADOX)

This step-by-step example describes how to use ADOX and Visual Basic .NET to create an Access database on the fly.

back to the top

Steps to Build Example
 Open a new Visual Basic .NET Console application. In Solution Explorer, right-click the References node, and then click Add Reference. In the Add Reference dialog box, click the COM tab, click '''Microsoft ADO Ext. 2.7 for DDL and Security, click Select to add it to the Selected Components section, and then click OK'''. Delete all of the code from the code window for Module1.vb.  Copy the following code and paste it in the code window: Imports ADOX

Module Module1

Sub Main

Dim cat As Catalog = New Catalog

cat.Create(&quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; & _                   &quot;Data Source=D:\AccessDB\NewMDB.mdb;&quot; & _                    &quot;Jet OLEDB:Engine Type=5&quot;)

Console.WriteLine(&quot;Database Created Successfully&quot;)

cat = Nothing

End Sub

End Module  Change the path to the new .mdb file as appropriate. Make sure the folder provided in the path exists. Press F5 to build and run the project.

The new .mdb file is created in Access 2000 (Jet 4.0) format. For a different Jet format, see the &quot;References&quot; section of this article.</li></ol>

back to the top

Troubleshooting
The Jet Provider requires that the path exists to create the new database. If you try to create a database file in a path that does not exist, you receive an exception. This exception can be caught by using a try...catch structure.

back to the top