尊敬的專業人員請幫我解決以下問題。 在我的.NET C#應用程序中有這樣的代碼:SqlConnection引發異常
SqlConnection connection = new SqlConnection(SQLCONNECTION_STRING);
它的工作原理奇妙的我的機器上,但拋出的Windows 2003服務器上的異常。該應用程序通過CGI運行並具有「完全信任」級別。 我試過幾個連接串,我認爲該字符串不會導致問題,因爲即使該代碼得到一個例外:
SqlConnection connection = new SqlConnection();
感謝。
我發現了兩個奇怪的事實:
- 如果我連接調試器來處理和簡單的跟蹤代碼它的工作原理。
- 它工作,如果我從命令行運行應用程序(而不是通過CGI根據需要)。
所以我猜CGI和SqlConnection交互有問題。有人知道嗎?
謝謝大家的回覆。
編輯補充:
這裏是我的連接字符串: 「供應商= SQLOLEDB;數據源=(本地);初始目錄=用戶;用戶ID =用戶;密碼=密碼;」
我也試了幾種可能的變體與那裏描述:http://www.connectionstrings.com/sql-server
請找到有關下面的異常信息:
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()
即使參數的構造函數給出了一個例外。所以我不認爲問題出在連接字符串中。我可以看到堆棧跟蹤報告了一些關於「路徑中的非法字符」的內容。所以我會試着鑽取並找出答案。但也許有人已經知道解決方案。
拋出什麼樣的異常?例外說什麼? – 2009-10-13 10:55:32
abd你的連接字符串是什麼樣的? – 2009-10-13 11:00:51