Dear professionals please help me with the following problem. In my .NET C# application a have this code:
SqlConnection connection = new SqlConnection( SQLCONNECTION_STRING );
It works marvelous on my development machine but throws an exception on Windows 2003 server. The application runs through CGI and has “Full trust” level. I've tried several connections strings and I think the string doesn't cause the issue because even this code gets an exception:
SqlConnection connection = new SqlConnection();
Thanks.
I found two weird facts:
So I guess something wrong with CGI and SqlConnection interaction. Does someone know about that?
Thanks everybody for responses.
Edited to add:
Here is my connection string: "Provider=SQLOLEDB;Data Source=(local);Initial Catalog=Users;User Id=user;Password=password;"
I've also tried several possible variants as described there: http://www.connectionstrings.com/sql-server
Please find information regarding the exception below:
The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.
at System.Data.SqlClient.SqlConnection..ctor()
at Test.Database.UpdateSQLServerDatabase(IDictionary`2 fields, String regName, StringBuilder regCode)
at Test.Program.Run()
Type: System.TypeInitializationException
InnerException: System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SqlConnectionFactory' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SqlPerformanceCounters' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.ArgumentException: Illegal characters in path.
at System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path)
at System.AppDomainSetup.VerifyDir(String dir, Boolean normalize)
at System.AppDomainSetup.get_ConfigurationFile()
at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)
at System.Configuration.ClientConfigurationHost.get_ConfigPaths()
at System.Configuration.ClientConfigurationHost.GetStreamName(String configPath)
at System.Configuration.ClientConfigurationSystem..ctor()
at System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
--- End of inner exception stack trace ---
at System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
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.Switch.InitializeConfigSettings()
at System.Diagnostics.Switch.InitializeWithStatus()
at System.Diagnostics.Switch.get_SwitchSetting()
at System.Diagnostics.TraceSwitch.get_Level()
at System.Data.ProviderBase.DbConnectionPoolCounters..ctor(String categoryName, String categoryHelp)
at System.Data.SqlClient.SqlPerformanceCounters..ctor()
at System.Data.SqlClient.SqlPerformanceCounters..cctor()
--- End of inner exception stack trace ---
at System.Data.SqlClient.SqlConnectionFactory..ctor()
at System.Data.SqlClient.SqlConnectionFactory..cctor()
--- End of inner exception stack trace ---
at System.Data.SqlClient.SqlConnection..cctor()
Even parameterless constructor gives an exception. So I don't think the problem is in the connection string. I can see stack trace tells something about "Illegal characters in path". So I will try to drill down and find out. But maybe someone already knows solution.
This problem is generally related to a problem in your configuration file. You might want to re-create that.
Thanks, Jivtesh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With