MySqlConnection Open failed , access denied even with impersonation
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开发者_C百科 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)
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.
精彩评论