OleDbCommand使用错误的路径 [英] OleDbCommand using wrong path

查看:86
本文介绍了OleDbCommand使用错误的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF应用程序中具有以下c#代码:

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); }

我的问题是,在VS调试器中单步执行代码时, command.ExecuteNonQuery行();引发异常。发生异常时,_targetCon.ConnectionString的值为 Provider = Microsoft.Jet.OleDb.4.0; Data Source = C:\AccessDatabases\APMS\unit3.mdb; ,并且_targetCon.DataSource的值是: C:\AccessDatabases\APMS\unit3.mdb 这是正确的路径。但是,ex2.Message的值为找不到文件'C:\Git_RB\AccessMigration\AccessLauncher\AccessLauncher.WPF\bin\Debug\Unit3.mdb'

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'"

如果我在VS之外运行该应用程序,那么我发现它仍在尝试在数据库中找到与该文件相同的文件夹中的文件。 exe:

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:

为什么命令对象忽略

推荐答案

检查所用SQL语句的实际值。它可能包含另一个表名称,而不是您期望的名称,例如由于字符串截断。

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.

这篇关于OleDbCommand使用错误的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆