OleDbCommand using wrong path

六眼飞鱼酱① 提交于 2019-12-13 19:40:53

问题


I have the following c# code in a WPF app:

var command = new OleDbCommand($"CREATE INDEX idx{index.ColumnName} ON {tableConfig.Name}({index.ColumnName})", _targetCon);
                    try
                    {
                        command.ExecuteNonQuery();
                    }
                    catch (Exception ex1) { _serilog.WriteError(METHOD_NAME, "Trouble adding index onto Access column", ex1); }

My problem is that when stepping through the code in the VS debugger, the line "command.ExecuteNonQuery();" is throwing an exception. At the time of the exception, the value of _targetCon.ConnectionString is "Provider=Microsoft.Jet.OleDb.4.0;Data Source=C:\AccessDatabases\APMS\unit3.mdb;" and the value of the _targetCon.DataSource is: C:\AccessDatabases\APMS\unit3.mdb This is the correct path. However, the value of ex2.Message is "Could not find file 'C:\Git_RB\AccessMigration\AccessLauncher\AccessLauncher.WPF\bin\Debug\Unit3.mdb'"

If I run the app outside of VS then I find that it's still trying to find the file in the database in the same folder as the exe:

Why is the command object ignoring the properties of its connection object and looking in the wrong path?


回答1:


Check the actual value of the SQL statement that you are using. It might contain another table name than the one you expect, e.g. due to string truncation.



来源:https://stackoverflow.com/questions/51281347/oledbcommand-using-wrong-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!