Search code examples
c#ms-access-2013

Not valid password Exception C# using ms-Access


I have programmed a scheduler that get the job and the job details that need to run from a Microsoft 2013 Access Database and execute them.

My problem is that every few runs one of the functions that connect to the database throw the exception "Not a Valid Password", what's weird is that the exception are thrown from different function each time, while most of the times those functions work perfectly. I really like to know what could cause those exceptions.

string SCHEDULER_ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\" + ConfigurationManager.AppSettings["SCHEDULER_DB_Path"] + ";Jet OLEDB:Database Password=someP@ssword";

public DataResponse getActiveJobsRecurrence(string Job)
    {
        String query;
        DataResponse DR = new DataResponse();
        query = " Select Job_name,to_date,from_Date,recurrence,MODIFY_BY_USER from JOB where Job_name='" + Job + "' ";
        DR.DataTable = new DataTable();
        try
        {
            using (OleDbConnection myConn = new OleDbConnection(SCHEDULER_ConnectionString))
            {
                using (OleDbCommand cmd = new OleDbCommand(query, myConn))
                {
                    myConn.Open();
                    OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
                    adapter.Fill(DR.DataTable);
                    myConn.Close();

                    return DR;
                }
            }
        }

        catch (Exception ex)
        {
            string owner = "none";
            string function = "getActiveJobsRecurrence()";
            string mes = ex.Message;
            string message;
            message = TruncateLongString(mes);
            writeInDatalog(message, owner, Job, function);
            DR.Message = ex.Message;
            DR.Successful = false;
            DR.DataTable = null;
            return DR;
        }
    }// find recurrence of the actives jobs

This is an example of one of the functions that throw this exception


Solution

  • It's all about the Encryption Method: First of all, remove the password, and then go into Access->File->Options->Client Settings->Advanced and check "use legacy encryption". fixed everything.