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.
For more information, please refer to the following:
317867.KB.EN-US HOW TO: Create a Microsoft Access Database Using ADOX and
Visual Basic
http://support.microsoft.com/default.aspx?scid=KB;EN-US;317867
Public | kbAudDeveloper
============================================================================
===
----------------------------------------------------------------------------
---
The information in this article applies to:
- Microsoft ADO.NET (included with the .NET Framework 1.1)
- Microsoft ADO.NET (included with the .NET Framework) 1.0 (Version: 1.0)
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
----------------------------------------------------------------------------
---
For a Microsoft Visual C# .NET version of this
article, see
KBLink:317881.KB.EN-US: .
IN THIS TASK
------------
- #1: SUMMARY
-
- #2: Requirements
- #3: Steps to Build
Example
- #4: Troubleshooting
- #4: 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.
Steps to Build Example
----------------------
1. Open a new Visual Basic .NET Console application.
2. In Solution Explorer, right-click the References node, and then
click Add Reference.
3. 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.
4. Delete all of the code from the code window for Module1.vb.
5. 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("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=D:\AccessDB\NewMDB.mdb;" & _
"Jet OLEDB:Engine Type=5")
Console.WriteLine("Database Created Successfully")
cat = Nothing
End Sub
End Module
6. 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 "References" section of this
article.
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.
REFERENCES
----------
For additional information about how to create a
table with a primary key through ADOX, click the following article
number to
view the article in the Microsoft Knowledge Base:
KBLink:252908.KB.EN-US: HOWTO: Create a Table with Primary Key Through
ADOX
For more details about the .NET Framework and the
COM Interop layer, visit the following Microsoft Web site:
Exposing
COM Components to the .NET Framework
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide
/html/cpconexposingcomcomponentstonetframework.asp
For more details about Microsoft Jet 4.0 Engine Type values,
visit the following Microsoft Web site:
Appendix C: Microsoft Jet 4.0
OLE DB Provider-Defined Property Values
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndao/h
tml/daotoadoupdate_topic15.asp
QUERY WORDS
===========
ADOX VB.NET
Sincerely,
Kevin
Microsoft Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! -
www.microsoft.com/security
--------------------
| From: "Soren Staun Jorgensen" <
[email protected]>
| Subject: Create new Access DB
| Date: Fri, 3 Oct 2003 08:53:09 +0200
| Lines: 8
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <
[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: 0x50c70a5c.adsl-fixed.tele.dk 80.199.10.92
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:62734
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Hi,
|
| Is it possible, using ADO.NET, to create a new Access db ??
| You cannot connect to the datasource before created
|
| Soren
|
|
|