|
| how to create a new database from c# |
|
|
|
|
| Messages |
|
Related Types |
This message was discovered on microsoft.public.dotnet.framework.odbcnet.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| Sam Jost |
Hi!
I want to write a program that creates an .jet database with c#, but I can't find how to create a database, only how to open it.
OleDbConnection MyConnection= new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=MyDb.mdb"); MyConnection.Open( );
just throws an exception because MyDb.mdb does not exist.
But I need a call to create MyDb.mdb - has anybody out there an idea how to create a database from c#???
It won't help me to create one with access, I can't do that every time I need one, I have to be able to do this fromthe program itself.
any help would be appreciated! Sam
|
|
|
| |
|
| |
| |
| Bob Beauchemin (VIP) |
An Access database? How about ADOX or DAO through interop? IDBDataSourceAdmin is not exposed by the OleDb data provider.
Bob Beauchemin Click here to reveal e-mail address
"Sam Jost" <Click here to reveal e-mail address> wrote in message news:a5gu33$nof$Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Sam Jost |
Uuh, you lost me there, I don't know nothing about ADOX or DAO or interop. I can just guess from your post that you know of no way to create db's from OleDb, and in ADOX/DAO are ways having to do with some IDBDataSourceAdmin call?
Sam [confused]
"Bob Beauchemin" <Click here to reveal e-mail address> schrieb im Newsbeitrag news:uZGo1zwvBHA.1528@tkmsftngp02... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Bob Beauchemin (VIP) |
Sorry.
IDBDataSourceAdmin is the OLE DB interface that ADOX (an extension to ADO) uses to allow creation of databases in Access. Since this is not exposed in the OleDb data provider, you cannot use the OleDb data provider to do this. You must either use the ADOX library (an extension to ADO) or DAO (Data Access Objects).
Since these are COM-based libraries, you can use them in .NET through COM interop. In fact, both are available by selecting "Add Reference" in Visual Studio and choosing the "COM" tab.
DAO = Microsoft DAO 3.6 Object Library ADOX = Microsoft ADO Ext. 2.7 for DDL and Security
Hope this helps, Bob Beauchemin Click here to reveal e-mail address
"Sam Jost" <Click here to reveal e-mail address> wrote in message news:a5h3r8$o1k$Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Hussein Abuthuraya(MSFT) |
Hi Sam/Bob,
Here is an excerpt from a new KB article that shows how to create an Access Database using C#:
Article Q317881 (Still not available on MSDN) ==================== Steps to Build Example ----------------------
1. Open a new Visual C# .NET console application.
2. In the Solution Explorer window, right-click the References node and select Add Reference.
3. In the Add Reference dialog box, click the COM tab and select Microsoft ADO Ext. 2.7 for DDL and Security. Click Select to add it to the "Selected Components". Click OK.
4. Delete all of the code from the code window for Class1.cs.
5. Copy the following code and paste it into the code window:
using System; using ADOX;
namespace ConsoleApplication1 { class Class1 { [STAThread] static void Main(string[] args) { ADOX.CatalogClass cat = new ADOX.CatalogClass();
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 = null;
} } }
6. Change the path to the new .mdb file as appropriate. Press F5 to build and run the project.
The new .mdb file will be created in Access 2000 (Jet 4.0) format. For a different Jet format, see "References."
Pitfalls --------
The Jet Provider requires the path to exist in order to create the new database. Attempting to create a database file in a directory that does not exist will result in an exception. This exception can be caught using a Try...Catch structure.
REFERENCES
For more details about the .NET Framework and the COM Interop layer, see:
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 on Microsoft Jet 4.0 Engine Type values, see:
Appendix C: Microsoft Jet 4.0 OLE DB Provider-Defined Property Values http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndao/html/daotoadoupdate_topic15.asp ========== End KB article
I hope this helps!
Thanks, Hussein Abuthuraya Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights. You assume all risk for your use. © 2002 Microsoft Corporation. All rights reserved
Are you secure? For information about the Microsoft Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit http://www.microsoft.com/security.
|
|
|
| |
|
| |
| |
| Sam Jost |
Yes, this did help, thank you! I still had to tlbimp msadox.dll and use the /r switch to use the resulting ADOX.dll with my program (VC.NET is not available yet in europe). It took me a few minutes to find the /r switch, it's not well documented ;)
thanks a bundle!! Sam -- "Hussein Abuthuraya(MSFT)" <Click here to reveal e-mail address> schrieb im Newsbeitrag news:z6LLvlyvBHA.2528@cpmsftngxa07... [Original message clipped]
l/cpconexposingcomcomponentstonetframework.asp [Original message clipped]
daotoadoupdate_topic15.asp [Original message clipped]
rights reserved [Original message clipped]
|
|
|
| |
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|