Resolved Error when dataAdaptor fills dataTable

PDS8475

Active member
Joined
Jun 25, 2019
Messages
41
Programming Experience
Beginner
Hi
I have a C# Form with a DataGridView (Records_dataGridView) that I am trying to fill from the access table "Donations" when the form loads.
I have a dataAdaptor (DA)
which fills a dataTable (DT)
which is the dataSource for Records_dataGridView
which can be seen in the code below
C#:
 private void Reports_Form_Load(object sender, EventArgs e)
        {
         
            string ConString = System.IO.File.ReadAllText("FixIT.con");
            ConString = ConString.Replace(System.Environment.NewLine, string.Empty);

            System.Data.OleDb.OleDbConnection connn = new System.Data.OleDb.OleDbConnection();
            string connsString = "Provider = Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + ConString;
            try
            {
                using (OleDbConnection connection = new OleDbConnection(connsString))
                {
                    using (OleDbCommand command = new OleDbCommand("Select * FROM Donations", connection))
                    {
                        command.CommandType = CommandType.Text;
                        using (OleDbDataAdapter DA = new OleDbDataAdapter(command))
                        {
                            using (DataTable DT = new DataTable())
                            {
                                DA.Fill(DT);
                                Records_dataGridView.DataSource = DT;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
The problem is I get the following exception when I try to load the form
System.Data.OleDb.OleDbException (0x80040E4D): No error message available, result code: DB_SEC_E_AUTH_FAILED(0x80040E4D).
at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OleDb.OleDbConnection.Open()
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at FixIT.Reports_Form.Reports_Form_Load(Object sender, EventArgs e) in C:\Users\Paul\source\repos\FixIT\FixIT\Reports_Form.cs:line 60
It appears that the error happens when the dataAdaptor tries to fill the dataTable but I don't know why.
 
Last edited:
The error code "DB_SEC_E_AUTH_FAILED" suggests a security related error -- specifically an authentication related error. By any chance is your application doing some kind of impersonation, or are you trying to access an Access database for which you do not have any permissions to access?
 
The error code "DB_SEC_E_AUTH_FAILED" suggests a security related error -- specifically an authentication related error. By any chance is your application doing some kind of impersonation, or are you trying to access an Access database for which you do not have any permissions to access?

Hi the connection string is used on multiple forms and works on the rest of the forms. It only fails on this form. So if it is related to the connection then it must be how the connection is set up on this form.
 
Hi the connection string is used on multiple forms and works on the rest of the forms. It only fails on this form. So if it is related to the connection then it must be how the connection is set up on this form.
Just tried after typing that message and for some reason it had lost connection to the database. I am storing the path to the database in a text file, I am using a open file dialog to save the path to the text file and for some reason this file got corrupted after I last tried the other forms which was a few hours ago. Which makes me look kind of silly, but thanks for your help I wouldn't of figured it out with out your help.
 
Is there something wrong with storing your connection string in a public readonly string
I'm not sure how to do this. The connection to the database has to be selectable and needs to be stored. But it would be more secure if the path was inside the database rather than to a text file.
 
lol If the path to the connection string was inside the database you'd never be able to connect to it to read it. I assume you meant if it were stored in your application?

If you tell what you're doing, I'm sure someone will help you to do what you want.

Oh my, look at your connection string. Learn to construct it properly - ConnectionStrings.com - Forgot that connection string? Get it here!
 

Latest posts

Back
Top Bottom