Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Programmatically creating a new Access DB [modified]

Programmatically creating a new Access DB [modified]

Scheduled Pinned Locked Moved Database
databasecsharphelptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rittjc
    wrote on last edited by
    #1

    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

    E 1 Reply Last reply
    0
    • R rittjc

      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

      E Offline
      E Offline
      Eric Dahlvang
      wrote on last edited by
      #2

      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

      R 1 Reply Last reply
      0
      • E Eric Dahlvang

        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

        R Offline
        R Offline
        rittjc
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups