我一直试图使用OLEDB和Access 2016获取数据库连接但不幸的是我不断返回错误:
%INCLUDE
从这部分代码:
System.Data.OleDb.OleDbException was unhandled
ErrorCode=-2147467259
HResult=-2147467259
Message=Not a valid file name.
Source=Microsoft Office Access Database Engine
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 Program_V1._0.Form1..ctor() in C:\Users\Tom\Documents\College\Computer_Science_Project _2017_Ver2.0\Program_Files\Program_V1.0\Program_V1.0\Form1.cs:line 24
at Program_V1._0.Program.Main() in C:\Users\Tom\Documents\College\Computer_Science_Project _2017_Ver2.0\Program_Files\Program_V1.0\Program_V1.0\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
即使在阅读了有关兼容性的问题之后,尽管我可能也看不到任何问题,我们将非常感谢任何帮助。
答案 0 :(得分:0)
当我复制你的连接字符串并将其粘贴到Notepad ++设置为" ANSI"编码我看
... Data Source=?C:\ ...
告诉我你的连接字符串包含非ANSI字符。进一步调查表明,神秘角色(上面显示为?
)实际上是不可见的Unicode角色U + 202A(左移嵌入式)。从连接字符串中删除该不可见字符应该可以解决问题。