gpt4 book ai didi

c# - 代码在 c# dll 和 powershell 中表现不同

转载 作者:太空宇宙 更新时间:2023-11-03 13:49:39 26 4
gpt4 key购买 nike

在C#中我有如下代码:

OleDbConnection cxn = New OleDbConnection();
cxn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='text;HDR=Yes;FMT=Delimited(,)';Data Source=" + System.IO.Path.GetDirectoryName(csvFilePath);
cxn.Open();
cxn.Close();

这段代码执行没有任何错误。

在 powershell 中同样的事情是这样的:

$cxn = new-object System.Data.OleDb.OleDbConnection
$cxn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='text;HDR=Yes;FMT=Delimited(,)';Data Source=" + [System.IO.Path]::GetDirectoryName($csvFilePath);
$cxn.Open();
$cxn.Close();

但是上面给出了一个错误:

Exception calling "Open" with "0" argument(s): "The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the machine"

我使用 64 位 Ms Windows 2008 Server R2 操作系统。我还看到另一篇文章说如果您将 Jet.OLEDB.4.0 更改为 ACE.OLEDB.12.0 它应该可以工作。它确实有效,但我不明白为什么同样的东西在 dll/exe 中“有效”,而在 powershell 中却失败了。

但是,我面临的问题是一个完全不同的问题。 Web 应用程序(wcf 服务)中存在类似的代码。我相信这在框架 3.5 (clr 2.0) 上运行。 Windows服务中也有类似的代码;失败的地方。

最佳答案

发生这种情况是因为您在 64 位 Powershell 中使用 Microsoft Jet 4.0(仅支持 32 位)。尝试从 32 位 Powershell(位于:“$env:WINDIR\syswow64\windowspowershell\v1.0\powershell.exe”)运行相同的命令

它在 IIS 中工作的原因是因为应用程序池设置为允许执行 32 位应用程序。

关于c# - 代码在 c# dll 和 powershell 中表现不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14055020/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com