作为服务运行时 OleDbConnection.Open 的问题
我们有一个 Nant 构建脚本,通过 SSH(Cygwin 和 Open SSH)运行来远程升级我们的数据库。通过 SSH 会话启动 Nant 脚本时,尝试建立数据库连接时会引发以下错误。但是,如果我直接登录服务器(使用与服务相同的帐户)并手动运行 Nant 脚本,则脚本会成功执行。
错误消息:
System.InvalidOperationException: .Net Framework 数据提供程序需要 微软数据访问 组件(MDAC)。请安装 微软数据访问组件(MDAC) 2.6 或更高版本。 ---> System.IO.FileNotFoundException:正在检索 COM 类工厂 具有 CLSID 的组件 {2206CDB2-19C1-11D1-89E0-00C04FD7A829} 由于以下错误而失败: 8007007e。
堆栈跟踪:
System.InvalidOperationException: The .Net Framework Data Providers require Microsoft Data Access Components(MDAC). Please install Microsoft Data Access Components(MDAC) version 2.6 or later.
---> System.IO.FileNotFoundException: Retrieving the COM class factory for component with CLSID {2206CDB2-19C1-11D1-89E0-00C04FD7A829} failed due to the following error: 8007007e.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Data.OleDb.OleDbConnectionInternal.CreateInstanceDataLinks()
at System.Data.OleDb.OleDbConnectionInternal.GetObjectPool()
--- End of inner exception stack trace ---
at System.Data.OleDb.OleDbConnectionInternal.GetObjectPool()
at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OleDb.OleDbConnection.Open()
at UpgradeDatabases.UpgradeDatabase.Execute()
在花了很多时间试图找出原因之后,我陷入了困境。以下是我的一些观察结果:
- 当我在同一台计算机上手动运行该脚本时(无需 SSH),该脚本可以完美运行。我什至可以使用运行 SSH 服务的同一用户手动运行该脚本。
- 由于 Nant 脚本在服务上下文中运行,因此该问题似乎与用户配置文件有关。
- 该脚本在安装了 .NET 3.5 的 Windows 2008 Server 上执行。我不认为 MDAC 会成为这里的问题,因为异常表明
- 一个站点指出它可能与 UPHClean(它是 Windows Server 2008 中的用户配置文件服务的一部分)有关。我无法确认这确实是问题所在。我在事件查看器中查看了事件 ID 1530,发现有几次出现,但它们与构建脚本的每次执行并不相关。
- 我安装了 本机SQL Server 2008 的 OleDb 提供程序 也会发生相同的错误。
有人对如何找出此问题的根本原因有任何建议吗?这似乎确实与代码在服务上下文中运行这一事实有关。我已经使用 Procmon 尝试追踪整个执行过程,但我没有找到罪魁祸首。提前致谢!
We have an Nant build script that we are running through SSH (Cygwin & Open SSH) to remotely upgrade our databases. When the Nant script is launched through an SSH session, the following error is thrown when it attempts to make a database connection. However, if I log in to the server directly (using the same account as the service) and run the Nant scripts by hand, the script executes successfully.
Error Message:
System.InvalidOperationException: The
.Net Framework Data Providers require
Microsoft Data Access
Components(MDAC). Please install
Microsoft Data Access Components(MDAC)
version 2.6 or later.
---> System.IO.FileNotFoundException: Retrieving the COM class factory for
component with CLSID
{2206CDB2-19C1-11D1-89E0-00C04FD7A829}
failed due to the following error:
8007007e.
Stack Trace:
System.InvalidOperationException: The .Net Framework Data Providers require Microsoft Data Access Components(MDAC). Please install Microsoft Data Access Components(MDAC) version 2.6 or later.
---> System.IO.FileNotFoundException: Retrieving the COM class factory for component with CLSID {2206CDB2-19C1-11D1-89E0-00C04FD7A829} failed due to the following error: 8007007e.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Data.OleDb.OleDbConnectionInternal.CreateInstanceDataLinks()
at System.Data.OleDb.OleDbConnectionInternal.GetObjectPool()
--- End of inner exception stack trace ---
at System.Data.OleDb.OleDbConnectionInternal.GetObjectPool()
at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OleDb.OleDbConnection.Open()
at UpgradeDatabases.UpgradeDatabase.Execute()
After spending lots of time trying to track down the cause, I am stuck. Here are some observations I have made:
- The script runs perfectly when I run it manually on the same machine (without SSH). I can even run the script manually, with the same user that the SSH service is running under.
- Since the Nant script is running under the context of a service, the issue seems to be related to the User Profile.
- The script is executing on a Windows 2008 Server with .NET 3.5 installed. I wouldn't assume that MDAC would be a problem here as the exception indicates
- One site states that it might be related to UPHClean (which is a part of the User Profile Service in Windows Server 2008). I haven't been able to confirm that this is actually the problem. I looked in the Event Viewer for Event ID 1530 and there are a few occurrences, but they don't correlate with each execution of the build script.
- I installed the native OleDb providers for SQL Server 2008 and the same error occurs.
Does anyone have any advice on how I can track down the root cause of this issue? It really seems to be related to the fact that the code is running under the context of a service. I've used Procmon to try to trace through the execution, but I haven't had any luck finding the culprit. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我还有“.Net Framework 数据提供程序需要 Microsoft 数据访问组件 (MDAC)。请安装 Microsoft 数据访问组件 (MDAC) 版本 2.6 或更高版本。”尝试通过 ssh 调用我的 Windows 程序时出错,但直接在服务器(Windows Server 2008 R2 Enterprise)上的 cygwin 终端中运行相同的程序时不会出错。我确信可以使用 cygwin 中的 openssh 来实现这一点。最终我发现,如果您在 ssh 调用中发送以下环境变量,它就可以工作:
因此,如果您像这样登录:
那么您应该能够成功运行您的程序。请注意,这假设您已在服务器上配置 sshd 以接受环境变量。您可以通过将以下行添加到 /etc/sshd_config 然后重新启动 sshd(net stop sshd 后跟 net start sshd)来完成此操作:
安装 AccessDatabaseEngine.exe(Microsoft Office Access 数据库引擎 2007)时(从 http://www.microsoft.com/en-us/download/confirmation。 aspx?id=23734) 它将一些文件放在 C:\Program Files (x86)\Common Files 下。
I also had the "The .Net Framework Data Providers require Microsoft Data Access Components(MDAC). Please install Microsoft Data Access Components(MDAC) version 2.6 or later." error when trying to invoke my Windows program over ssh, but not when running the same program directly in a cygwin terminal on the server (Windows Server 2008 R2 Enterprise). I felt sure this could be made to work using openssh in cygwin. Eventually I found that it could be made to work if you sent the following environment variable in the ssh call:
So if you logged in like so:
Then you should be able to run your program successfully. Note this assumes you have already configured sshd on the server to accept the environment variable. You can do that by adding the following line to /etc/sshd_config and then restarting sshd (net stop sshd followed by net start sshd):
When AccessDatabaseEngine.exe (Microsoft Office Access database engine 2007) is installed (download it from http://www.microsoft.com/en-us/download/confirmation.aspx?id=23734) it puts some files under C:\Program Files (x86)\Common Files.
该问题肯定与 Cygwin + OpenSSH 有关。我最终安装了 WinSSHD 并且我的问题得到了解决。因此,为了将来的参考,请警惕在 Windows Server 2008 上运行的 Cygwin + OpenSSH。我希望这会有所帮助!
The problem was definitely related to Cygwin + OpenSSH. I ended up installing WinSSHD and my issue was resolved. So for future reference, be wary of Cygwin + OpenSSH running on Windows Server 2008. I hope this helps!
在运行连接 Access 数据库的 C# 程序时,Windows 7 + OpenSSH(OpenSSH_6.5p1、OpenSSL 1.0.1f 2014 年 1 月 6 日)上出现同样的问题。
我已经
在 /etc/profile 文件中添加了。
希望这有帮助。
Same issue on Windows 7 + OpenSSH (OpenSSH_6.5p1, OpenSSL 1.0.1f 6 Jan 2014) while running C# program connecting Access database.
I've added
in /etc/profile file.
Hope this help.