【发布时间】:2018-10-11 18:00:41
【问题描述】:
在你们告诉我这是重复之前,你们应该知道我已经完成了几乎所有我能找到的答案。但我仍然无法解决这个问题。
我已尝试在 Computer\HKEY_CLASSES_ROOT\CLSID 中为所有 OLEDB 添加注册表值,如下所示:-
Value Name: OLEDB_SERVICES
Data Type: REG_DWORD
Value: 0xFFFFFFFF
-> 我尝试从连接字符串和数据库中的密码中删除特殊字符。 -> 我试过使用 Integrated Security=True , Integrated Security=SSPI, 持久安全信息=True
我的连接字符串是:- `
<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 驱动程序 12、14 和 16,但选择使用 12,因为它在我看到的教程中使用。我正在使用 Access 2016 和 Visual Studio 2017。
【问题讨论】:
-
不知道你在看哪个教程,但是任何教你连接字符串构建sql语句的教程都不是好教程。
-
@Steve sql语句因为换行而有串联,是VS自己自动添加的。
-
使用参数避免sql注入和格式化错误。永远不要将密码存储在数据库中。
-
没关系。始终在每种情况下使用参数。如果您有一个名为“O'Brien”的用户,你猜怎么着?错误。发布您收到的整个错误消息。
-
你的异常发生在连接上,而不是查询上,所以修复它。
标签: c# ms-access visual-studio-2017 ms-access-2016