Database Security Failure

Ok, I'm stumped on this one.  I created an Access database, located it on my "C:\" drive and can read it with no problem.  All of the fields in the database are Text.

However, when I try to insert a row I get this rather criptic (to me at least) message (from the catch phrase):

Error trying to add new record
Error: No error information available: DB_SEC_E_AUTH_FAILED(0x80040E4D)

After stepping thru the code, I found the error occurs on this line:

    conn.Open();

Anyone have an idea what's causing this

private void buttonAdd_Click(object sender, System.EventArgs e)

{

    if ( buttonAdd.Text == "&Add" )
    {
        ResetTextbox();
        textboxHoldFirstName.Location = new Point( 92, 10 );
       
textboxHoldLastName.Location = new Point( 200, 10 );
       
buttonAdd.Text = "&Save";
    }
   
else
   
{
       
VerifyFields();
       
try
        
{
            
OleDbConnection conn = new OleDbConnection( strPhnBkConnect );
             string strinsertCommand = sqlInsert +
                     "'" + textboxHoldFirstName.Text + "'" + ", " +
                     "'" + textboxHoldLastName.Text + "'" + ", " +
                     "'" + textBoxSpouse.Text + "'" + ", " +
                     "'" + textBoxAddress.Text + "'" + ", " +
                     "'" + textBoxCity.Text + "'" + ", " +
                     "'" + textBoxState.Text + "'" + ", " +
                     "'" + textBoxZipCode.Text + "'" + ", " +
                     "'" + textBoxPhone.Text + "'" + ", " +
                     "'" + textBoxCellPhone.Text + "'" + ", " +
                     "'" + textBoxWorkPhone.Text + "'" + ", " +
                     "'" + textBoxExtension.Text + "'" + ", " +
                     "'" + textBoxEmail.Text + "'" + ", " + ")";

              OleDbCommand addCmnd = new OleDbCommand(strinsertCommand, conn);
              conn.Open();
              addCmnd.ExecuteNonQuery();
              conn.Close(); 
          }

         catch (OleDbException ox )
         {
             MessageBox.Show( "Error trying to add new record" +
                                       "\nError: " + ox.Message,
                                       "Database Error"
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
          buttonAdd.Text = "&Add";
    }

} //* end method buttonAdd_Click




Answer this question

Database Security Failure

  • simonw.

    Thank you Konstantin.  It's weird, but it works fine now.  I never knew about that link either, copied that to my 'Favorites'.

    Rhubarb

  • Jon Peltier

    Thank you Konstantin.  The database isn't password protected.  Here is the connection strings:

    private string strPhnBkConnect = "provider=Microsoft.JET.OLEDB.4.0;" +
                                                "data source=";

    private string strDbPath = @"C:\MDB\Addresses\addresses.mdb";

    I restructured the code in the try statement like this:

          string strAddConnect = "";
          if ( buttonAdd.Text == "&Add" )
          {
              ResetTextbox();
              textboxHoldFirstName.Location = new Point( 92, 10 );
              textboxHoldLastName.Location = new Point( 200, 10 );
              buttonAdd.Text = "&Save";
         }
         else
         {
              VerifyFields();
              try
              {
                   strAddConnect = strPhnBkConnect + strDbPath;
                   OleDbConnection conn = new OleDbConnection( strAddConnect );

                   .  .  . 

    but still receive the error trying to open the database. 



  • Kunjal Karamshi

    AFAIK you still need to specify the user (w.o. password). Take a look at http://www.connectionstrings.com

  • TimFröglich

    Check strPhnBkConnect if it really contains valid connection string. It seems like you're connecting to DB with wrong password

  • Database Security Failure