2013-07-05 82 views
0

我在嘗試連接到sql server時出現了我的winform中的錯誤,不明白爲什麼。這是錯誤:配置系統初始化失敗。SQL Server連接錯誤:配置系統初始化失敗

這裏是我的代碼:

 connectionString = ConfigurationManager.ConnectionStrings("Connect5").ConnectionString 

     Dim myConnection As New SqlConnection(connectionString) 
     myConnection.Open() 

這裏是我的app.config:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > 
<section name="TestConsoleApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
</sectionGroup> 
<system.diagnostics> 
<sources> 
<source name="DefaultSource" switchName="DefaultSwitch"> 
      <listeners> 
       <add name="FileLog"/> 
       <!-- Uncomment the below section to write to the Application Event Log --> 
       <!--<add name="EventLog"/>--> 
      </listeners> 
     </source> 
    </sources> 
    <switches> 
     <add name="DefaultSwitch" value="Information" /> 
    </switches> 
    <sharedListeners> 
     <add name="FileLog" 
      type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" 
      initializeData="FileLogWriter"/> 
     <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log --> 
     <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> --> 

    </sharedListeners> 
</system.diagnostics> 
<connectionStrings> 
<add name="Connect5" connectionString="Data Source=asapinc.local\SQLEXPRESSSERVER;Initial Catalog=ASAP_DATABASE; User ID=ASAP;Password=CLEAN1"/> 

+0

我懷疑這是它看到這個詞xml紅色下劃線,但我注意到你在分號和用戶ID之間後有一個空格: ';用戶ID ='在你的配置文件中。 – Tim

回答

0

你應該在這條線

<?xml version="1.0" encoding="utf-8" ?> 

Unexpected XML declaration. The XML Declaration must be the first node in the document and no white space characters are allowed to appears before it

+0

對不起,在app.config文件中沒有任何地方出現紅色下劃線 – Will

+0

但是在第一行之前是否有空格? – Steve

相關問題