Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create database

Status
Not open for further replies.

fotinaki

Programmer
Jun 4, 2003
12
0
0
FR
How can I create a MS Access database using ADO.NET?
 

Neither ADO.NET nor ActiveX Data Object (ADO) provides the means to create Microsoft Access Database. However, we 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.

1. Open a new Visual Basic .NET Windows application.
2. In Solution Explorer, right click the References node, and then click Add References.
3. In the Add References dialog box, click 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. Make sure to add reference to ADOX class library namespace (Imports ADOX).
5. Change the path to the new .mdb file as appropriate.
6. Make sure the folder provided in the path exists. If path name is not specified, the database will be created in your application folder.
7. Create a Button control named btnCreateDatabase on the form and copy the following code in the click event of the button:

Imports ADOX

Private Sub onCreateDatabaseClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateDatabase.Click
Dim cat As New Catalog()

Try
'Create NewDB Database.
'Change the path to the new .mdb file as appropriate. Make sure the folder
'provided in the path exists. If you path name is not specified, the
'database will be created in your application folder.
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\NewDB.mdb")

MessageBox.Show("Database Created.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)

Catch Excep As System.Runtime.InteropServices.COMException
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

Finally
cat = Nothing
End Try
End Sub


 
Thanks,
...that was what I wanted to avoid, using ADOX, adding a reference...but there isn't another way...
 
Hi there is no way to create a access database in code with ado.net, (for sql there is)
here are some links.
From Microsoft below is the link
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.
_____________________________________________________

________________________________________________________
It's a real pain to use com!
 

as chaimUsa said there is no other way, u need to Persist with ADOX

 
Yes I made a separate exe for create database in code in .net app I only use .net components not com,
hope Microsoft does something for access not only ms-sql
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top