BEFORE you guys tell me that this is a duplicate, You should know that I have gone through almost every answer I could find. But still i have not been able to solve this issue.
I have tried adding registry values in Computer\HKEY_CLASSES_ROOT\CLSID
for all OLEDBs like following:-
Value Name: OLEDB_SERVICES
Data Type: REG_DWORD
Value: 0xFFFFFFFF
-> I have tried removing special characters from my password in connection string and Database. -> I have tried using Integrated Security=True , Integrated Security=SSPI, Persist Security Info=True
My Connection String is:- `
<appSettings>
<add key="Con" value="Provider=Microsoft.ACE.OLEDB.12.0;Jet OLEDB:Database Password=Preeya1 Data Source=C:\Users\Aqore-User\Desktop\Accounting\AccountingDbEnc.accdb"/>
</appSettings>
`
My code is:-
OleDbDataAdapter da = new OleDbDataAdapter
("Select * from [Users] where " +"[User]='"+UsernameTextbox.Text+"' and " +
"[Password]='"+PasswordTextbox.Text+"'", conn);
DataSet ds = new DataSet();
da.Fill(ds); <<--THIS IS WHERE ERROR OCCURS
if (ds.Tables[0].Rows.Count > 0)
{
MainForm mf = new MainForm();
mf.Show();
this.Hide();
}
In the AccessDB the DataType of User is 'Long Text' and of Password is 'Short Text'
Entire Exception:-
System.Data.OleDb.OleDbException
HResult=0x80040E21
Message=Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
Source=System.Data
StackTrace:
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(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at Accounting_Project.Project.LoginForm.LoginButton_Click(Object sender, EventArgs e) in C:\Users\Aqore-User\source\repos\Accounting Project\Accounting Project\Project\LoginForm.cs:line 45
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at MetroFramework.Controls.MetroButton.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Accounting_Project.Program.Main()
Any help would be appreciated,Any article or guidance that can help me understand and solve this issue is appreciated.
NOTE:- I have all Microsoft Access Driver 12 and 14 and 16 but chose to use 12 as it was used in the tutorials I saw. I am using Access 2016 and Visual Studio 2017.
If this does not fix your issue post the complete exception, stack trace, and type.
const string sqlStatement = "Select * from [Users] WHERE [User]= ? AND [Password]= ?";
OleDbDataAdapter da = new OleDbDataAdapter();
OleDbCommand command = new OleDbCommand(sqlStatement, conn);
command.Parameters.Add(new OleDbParameter("@username", OleDbType.LongVarChar, 200)).Value = UsernameTextbox.Text;
command.Parameters.Add(new OleDbParameter("@password", OleDbType.VarChar, 100)).Value = PasswordTextbox.Text;
da.SelectCommand = command;
DataSet ds = new DataSet();
da.Fill(ds);
User contributions licensed under CC BY-SA 3.0