Programmatically creating a new Access DB [modified]
-
You can't get there from here...I always found that statement ironic. You hear it a lot when asking directions. It is like the problem I am having in creating a new Access database from ADO.NET programmatically. First, you need a connection. This connection needs a connection string. The connection string has to have the path of the new database or it gripes about no Data Source. But when you put the new database name and path connection string it complains that the Data Source does not exist. How do you do this? Any gurus know how to do this? My plan was to: OdbcConnection myConn = new OdbcConnection("Provider=blah..blah"); OdbcCommand myCommand = new OdbcCommand("CREATE DATABASE MyDbPath", myConn); myComm.Open(); myCommand.ExecuteNonQuery(); ... How do you get there from here? Thanks in advance! -- modified at 22:48 Monday 19th June, 2006
-
You can't get there from here...I always found that statement ironic. You hear it a lot when asking directions. It is like the problem I am having in creating a new Access database from ADO.NET programmatically. First, you need a connection. This connection needs a connection string. The connection string has to have the path of the new database or it gripes about no Data Source. But when you put the new database name and path connection string it complains that the Data Source does not exist. How do you do this? Any gurus know how to do this? My plan was to: OdbcConnection myConn = new OdbcConnection("Provider=blah..blah"); OdbcCommand myCommand = new OdbcCommand("CREATE DATABASE MyDbPath", myConn); myComm.Open(); myCommand.ExecuteNonQuery(); ... How do you get there from here? Thanks in advance! -- modified at 22:48 Monday 19th June, 2006
Intriguing dilemma. I searched a little, and only came up with this: http://support.microsoft.com/kb/317881/EN-US/[^] The gist of it is that you need to use
Microsoft ADO Ext. 2.7 for DDL and Security.
Build an Access Database Open a new Visual C# .NET console application. In Solution Explorer, right-click the References node and select Add Reference. On the COM tab, select Microsoft ADO Ext. 2.7 for DDL and Security, click Select to add it to the Selected Components, and then click OK. Delete all of the code from the code window for Class1.cs. Paste the following code 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; } }
}
Change the path to the new .mdb file as appropriate, and then press F5 to build and run the project. The new .mdb file will be created in Access 2000 (Jet 4.0) format. ---------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters
-
Intriguing dilemma. I searched a little, and only came up with this: http://support.microsoft.com/kb/317881/EN-US/[^] The gist of it is that you need to use
Microsoft ADO Ext. 2.7 for DDL and Security.
Build an Access Database Open a new Visual C# .NET console application. In Solution Explorer, right-click the References node and select Add Reference. On the COM tab, select Microsoft ADO Ext. 2.7 for DDL and Security, click Select to add it to the Selected Components, and then click OK. Delete all of the code from the code window for Class1.cs. Paste the following code 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; } }
}
Change the path to the new .mdb file as appropriate, and then press F5 to build and run the project. The new .mdb file will be created in Access 2000 (Jet 4.0) format. ---------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters
Thanks Eric. That is a very inelegant solution. Looks like I am stuck with using it. Surprizing that there is not a better way. What if the end user does not have ADO 2.7 on his machine? Great job finding that buddy! It confirms the problem and at least offers a solution, elegant or not. Thanks again.