views:

387

answers:

5

Hello, 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.

+1  A: 
SqlConnection connection = new SqlConnection();

should not throw an exception. Are you sure it is this line? Can you give more details on exception thrown, ideally with stack trace. Include your connection string with sensitive data replaced.

dove
A: 

Thank you guys for response.

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.

Thanks.

Slava
Your server is `(local)`. Is there a local instance of SQL Server running on both machines?
Ken Keenan
No, there isn't. Actually I've found that on development machine the issue causes too.
Slava
A: 

Try the following:

string str="Data Source=[YourServer];Initial Catalog=yourdb;User ID=sa;Password=sa;";
SqlConnection connection = new SqlConnection(str);
Himadri
A: 

I found two weird facts: 1) It works if I connect debugger to process and simple trace the code. 2) It works if I run the application from command line (not through CGI as required).

So I guess something wrong with CGI and SqlConnection interaction. Does someone know about that?

Thanks everybody for responses.

Slava
A: 

Hi,

This problem is generally related to a problem in your configuration file. You might want to re-create that.

Thanks, Jivtesh

Jivtesh