在你们告诉我这是重复的之前,您应该知道我已经找到了几乎所有可以找到的答案。但是我仍然无法解决这个问题。
我尝试在Computer\HKEY_CLASSES_ROOT\CLSID
中为所有OLEDB添加注册表值,如下所示:-
Value Name: OLEDB_SERVICES
Data Type: REG_DWORD
Value: 0xFFFFFFFF
->我尝试从连接字符串和数据库中的密码中删除特殊字符。 ->我尝试使用Integrated Security = True,Integrated Security = SSPI, 坚持安全信息=真
我的连接字符串为:- `
<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>
`
我的代码是:-
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();
}
在AccessDB中,用户的数据类型为“长文本”,密码的数据类型为“短文本”
整个异常:-
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()
任何帮助将不胜感激,任何可以帮助我理解和解决此问题的文章或指南都将受到赞赏。
注意:-我拥有所有Microsoft Access Driver 12、14和16,但是选择使用12,因为我在教程中看到过。我正在使用Access 2016和Visual Studio 2017。
答案 0 :(得分:1)
如果这不能解决您的问题,请发布完整的异常,堆栈跟踪并输入。
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);