【问题标题】:Why am I getting "Microsoft][ODBC Text Driver] '(unknown)' is not a valid path"?为什么我会收到“Microsoft][ODBC Text Driver] '(unknown)' is not a valid path”?
【发布时间】:2014-10-04 21:58:15
【问题描述】:

根据 OP here 发布的代码(理论上它应该适用于我拥有的格式良好的测试文件),我正在尝试将 CSV 文件的内容分配给 DataGridView :

string conStr = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + selectedFile + ";Extensions=csv,txt";

OdbcConnection conn = new OdbcConnection(conStr);

OdbcDataAdapter da = new OdbcDataAdapter("Select * from [" + Path.GetFileName(selectedFile) + "]", conn);
DataTable dt = new DataTable(selectedFile);
da.Fill(dt);

dataGridViewFileContents.DataSource = dt;

da.Dispose();
conn.Close();
conn.Dispose();

运行我的测试场景时,selectedFile 的值为C:\PersianUtil\persianUtilOutput.txt,conStr 的值为Driver={Microsoft Text Driver ( .txt;.csv)};Dbq=C:\PersianUtil\persianUtilOutput.txt;Extensions=csv,txt

但在“da.Fill(dt);”行我得到:

System.Data.Odbc.OdbcException was unhandled
  HResult=-2146232009
  Message=ERROR [HY024] [Microsoft][ODBC Text Driver] '(unknown)' is not a valid path.  Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
ERROR [01000] [Microsoft][ODBC Text Driver]General Warning Unable to open registry key 'Temporary 
(volatile) Jet DSN for process 0x26d4 Thread 0x11d8 DBC 0x8649fd4 Text'.
ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed
ERROR [01000] [Microsoft][ODBC Text Driver]General Warning Unable to open registry key 'Temporary 
(volatile) Jet DSN for process 0x26d4 Thread 0x11d8 DBC 0x8649fd4 Text'.
ERROR [HY024] [Microsoft][ODBC Text Driver] '(unknown)' is not a valid path.  . . .

我在这里做错了什么或没有做错什么?

如果有更好的方法/替代方法,我也愿意。

【问题讨论】:

    标签: c# csv datagridview odbc


    【解决方案1】:

    我知道这是个老问题,但我们开始在以前工作的文件上收到此错误。重新启动 Excel 后,我们可以再次打开它,直到下次出现错误。

    似乎 Excel 正在发挥作用,而不是像 explained nicely here 那样关闭一些独占锁。

    你能解决它吗?

    【讨论】:

    • 我完全不记得了,所以如果我记得,它就会退回到记忆的黑暗深处。
    猜你喜欢
    • 2020-09-13
    • 2022-06-22
    • 1970-01-01
    • 2018-10-28
    • 2011-10-20
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    相关资源
    最近更新 更多