我收到此错误:
失败:
System.TypeInitializationException: The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section ServiceSettings/TycheConnectionString. (C:\KR_workspace\Alpha\Tyche\Applications\KPlusSynchronizer\KPlusSynchronizer\KPlusSynchronizerConsole\bin\Debug\KPlusSynchronizerConsole.vshost.exe.config line 17)
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 System.Data.Common.ADP.IsSysTxEqualSysEsTransaction()
at System.Data.Common.ADP.NeedManualEnlistment()
at System.Data.Odbc.OdbcConnection.Open()
at KPlusSynchronizer.Kplus.GetDataFromKplus(String kplusConnection, String sp) in c:\KR_workspace\Alpha\Tyche\Applications\KPlusSynchronizer\KPlusSynchronizer\KPlusSynchronizer\KPlus\Kplus.cs:line 24
at KPlusSynchronizer.Kplus..ctor(String kplusConnection, String sp) in c:\KR_workspace\Alpha\Tyche\Applications\KPlusSynchronizer\KPlusSynchronizer\KPlusSynchronizer\KPlus\Kplus.cs:line 16
at KPlusSynchronizer.Synchronizer.Synchronize(String tycheTable, String tycheSp, String kplusSp) in c:\KR_workspace\Alpha\Tyche\Applications\KPlusSynchronizer\KPlusSynchronizer\KPlusSynchronizer\KPlusSynchronizer.cs:line 34:
当我运行我的应用程序时。这是我的应用配置:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="ServiceSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="KPlusSynchronizerConsole.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
<sectionGroup name="TablesToSynchronize" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="KPlusSynchronizerConsole.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<ServiceSettings>
<TycheConnectionString value="Data Source=xxxxx;Initial Catalog=xxxxxx;Integrated Security=True" />
<KplusConnectionString value="Driver={Adaptive Server Enterprise};UID=xxxxx;PWD=xxxxx;Database=xxxxxx;Server=xxxxx;Port=4130;" />
<LogFiles value="true" />
</ServiceSettings>
<TablesToSynchronize>
<Table name="Table1" tycheSp="xxxxx" kplusSp="xxxx"/>
<Table name="Table2" tycheSp="xxxxx" kplusSp="xxxx"/>
<Table name="Table3" tycheSp="xxxxx" kplusSp="xxxx"/>
</TablesToSynchronize>
</configuration>
因此,当我使用connectionstring打开与DB的连接时会抛出错误。我想要一些帮助如何设置它。我需要两个configSections吗?这甚至可能吗?
我想使用这种om格式而不是appSettings
答案 0 :(得分:0)
尝试
<ServiceSettings>
<KPlusSynchronizerConsole.Properties.Settings>
<TycheConnectionString value="Data Source=xxxxx;Initial Catalog=xxxxxx;Integrated Security=True" />
<KplusConnectionString value="Driver={Adaptive Server Enterprise};UID=xxxxx;PWD=xxxxx;Database=xxxxxx;Server=xxxxx;Port=4130;" />
<LogFiles value="true" />
</KPlusSynchronizerConsole.Properties.Settings>
</ServiceSettings>
如果你看一下你的规范:
<sectionGroup name="ServiceSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="KPlusSynchronizerConsole.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
应该清楚的是,你告诉它期望一个名为“KPlusSynchronizerConsole.Properties.Settings”的部分,因此你应该有一个部分!
你需要做同样的事情
<TablesToSynchronize>...