MySqlConnection 打开失败,即使模拟也拒绝访问
我的类库无法使用 MySql .net 连接器建立 mysql 连接。如果我通过使用类库的命令行控制台应用程序运行它,它可以连接。但当我使用 PHP COM 加载/运行 .net 程序集时,它失败了。类库具有模拟用户的模拟代码。为了进行测试,我模拟了我自己的用户帐户。
查看堆栈跟踪。访问 C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\machine.config 需要什么凭据? 在 .NET 程序集中模拟的正确代码是什么(它也是 COM 感知的)?
2011/08/17 10:11:52.653 AM - The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception.
2011/08/17 10:11:52.653 AM - at System.Transactions.Transaction.get_Current()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at MineForums.Miner.Process(Int32 forumId, String mineDirectory)
2011/08/17 10:11:52.653 AM - Configuration system failed to initialize
2011/08/17 10:11:52.653 AM - at System.Transactions.Transaction.get_Current()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at MineForums.Miner.Process(Int32 forumId, String mineDirectory)
2011/08/17 10:11:52.965 AM - System.TypeInitializationException: The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Access is denied.
(C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\machine.config) ---> System.Security.SecurityException: Access is denied.
at System.Security.Principal.WindowsImpersonationContext.Undo()
at System.Security.Principal.WindowsImpersonationContext.Dispose(Boolean disposing)
at System.Security.Principal.WindowsImpersonationContext.Dispose()
at System.Configuration.BaseConfigurationRecord.InitConfigFromFile()
The Zone of the assembly that failed was:
MyComputer
--- End of inner exception stack trace ---
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
--- End of inner exception stack trace ---
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
at System.Diagnostics.DiagnosticsConfiguration.Initialize()
at System.Diagnostics.DiagnosticsConfiguration.get_Sources()
at System.Diagnostics.TraceSource.Initialize()
at System.Diagnostics.TraceSource.get_Switch()
at System.Transactions.Diagnostics.DiagnosticTrace..cctor()
--- End of inner exception stack trace ---
at System.Transactions.Transaction.get_Current()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at MineForums.Miner.Process(Int32 forumId, String mineDirectory)
My Class library failed to make a mysql connection using MySql .net connector . It can connect if I run it thru a command line console app that use the class library. But it fails when I use PHP COM to load/run the .net assembly . The class library has impersonation code to impersonate a user . For testing , I impersonate my own user account.
Looking at the stack trace. What credential is needed to access C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\machine.config ?
What is the proper code to impersonate in a .NET assembly (it is also COM aware) ?
2011/08/17 10:11:52.653 AM - The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception.
2011/08/17 10:11:52.653 AM - at System.Transactions.Transaction.get_Current()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at MineForums.Miner.Process(Int32 forumId, String mineDirectory)
2011/08/17 10:11:52.653 AM - Configuration system failed to initialize
2011/08/17 10:11:52.653 AM - at System.Transactions.Transaction.get_Current()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at MineForums.Miner.Process(Int32 forumId, String mineDirectory)
2011/08/17 10:11:52.965 AM - System.TypeInitializationException: The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Access is denied.
(C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\machine.config) ---> System.Security.SecurityException: Access is denied.
at System.Security.Principal.WindowsImpersonationContext.Undo()
at System.Security.Principal.WindowsImpersonationContext.Dispose(Boolean disposing)
at System.Security.Principal.WindowsImpersonationContext.Dispose()
at System.Configuration.BaseConfigurationRecord.InitConfigFromFile()
The Zone of the assembly that failed was:
MyComputer
--- End of inner exception stack trace ---
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
--- End of inner exception stack trace ---
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
at System.Diagnostics.DiagnosticsConfiguration.Initialize()
at System.Diagnostics.DiagnosticsConfiguration.get_Sources()
at System.Diagnostics.TraceSource.Initialize()
at System.Diagnostics.TraceSource.get_Switch()
at System.Transactions.Diagnostics.DiagnosticTrace..cctor()
--- End of inner exception stack trace ---
at System.Transactions.Transaction.get_Current()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at MineForums.Miner.Process(Int32 forumId, String mineDirectory)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在命令提示符处
cacls "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\machine.config"
将显示谁/什么对该文件具有权限。您还想验证文件上方所有目录的访问权限。cacls "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\machine.config"
at a command prompt will show who/what has permissions on that file. You'd want to verify access rights for all the directories above the file as well.