none
Creating a New Access Database RRS feed

  • Question

  • Hello,

    I have a program i am making that is going to need to be able to store information in a database based on usr prefreances. I have already made the neassary code to create the defualt tables and such for MySQL, MSSQL, Excel, and Basic CVS Text Files, but i seem to having a issue making the Access database. I am using Microsoft.Office.Interop for the Excel and Access.

    Here is the code for the MDB creation.

    Code Snippet

    private void CreateNewMDB(string Target)
    {
        Database oData;
        Access.Application oAccess;

        try
        {
            oAccess = new Access.Application();
            oAccess.Visible = false;
            oAccess.NewCurrentDatabase(Environment.CurrentDirectory + @"\" + Target + ".mdb");
            oData = oAccess.CurrentDb();
            oData.NewPassword("", "password");
            BuildDefualts(oData, Target);
            oData.Close();
            oAccess.CloseCurrentDatabase();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }



    Now when it goes to pass the Current Database to the dao.database variable i get a error saying it can not load the Object Type Libary/DLL. What have i done wrong? I can't seem to locate much information pretaining to MS Access and the Interop only Excel and Word.
    Wednesday, September 12, 2007 1:56 PM

Answers

  • Yes, you can set the database password:


    Code Snippet
    cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                         "Data Source=C:\Test Files\Access2007.mdb;" & _
                         "Jet OLEDB:Engine Type=5;" & _
                         "Jet OLEDB:Database Password='password'"

     

     

     

     

    Thursday, September 13, 2007 2:16 PM

All replies

  • Instead of using automation and Microsoft Access why not use the ADOX library instead?

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2119802&SiteID=1

     

     

     

    Thursday, September 13, 2007 1:14 PM
  • I didn't use it becuase as far as i could tell the ADOX would not let me set a password to the new database like the automation would. Though i could be mistaken since this is the first time i am not just including the mdb in in the project/installer.
    Thursday, September 13, 2007 1:22 PM
  • Yes, you can set the database password:


    Code Snippet
    cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                         "Data Source=C:\Test Files\Access2007.mdb;" & _
                         "Jet OLEDB:Engine Type=5;" & _
                         "Jet OLEDB:Database Password='password'"

     

     

     

     

    Thursday, September 13, 2007 2:16 PM
  • Ah, thank you. Like i said. Most of my stuff that i need a database for information storage they usually get created and packaged with the program. This is the first time its optional. So i didn't want to package anything that was not needed be the user.
    Thursday, September 13, 2007 2:33 PM