我一直在嘗試使用OLEDB和Access 2016不幸的是獲得一個數據庫連接然而,我還是不斷返回的錯誤:C#OLEDB數據庫連接使用Access 2016
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:
從這段代碼:
//Database Connection
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Tom\Documents\College\Computer_Science_Project _2017_Ver2.0\Program_Files\Program_V1.0\Program_V1.0\Databases\DecodeTimes.accdb;
Persist Security Info=False;";
connection.Open();
label3.Text = " - Database Connected - ";
connection.Close();
試試看,即使在閱讀關於兼容性的問題後,我也無法看到任何問題,任何幫助將不勝感激。
我看起來像你可能有一個意外的空間在文件名。 –
@MattWarren不幸的是,我認爲文件名是完好的,因爲它是從文件屬性直接複製,將檢查,雖然,謝謝。 – Tom
縮短文件路徑並從簡單的文件路徑在本地測試它..文件名與空格需要引用周圍的行情 'Computer_Science_Project _2017_Ver2.0'應該是'Computer_Science_Project_2017_Ver2.0' – MethodMan