无法读取XML文件

时间:2014-05-11 11:59:38

标签: c# .net xml

我正在尝试从我的.NET项目中的XML文件中进行简单的读取。

我会分享一些代码,也许有人会帮我弄清楚我做错了什么

XML文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <appSettings>
    <add key = "connection" value="Data Source=(local); Initial Catolog = Airline_Reservation; Integrated Security=SSPI"/>    
  </appSettings>
</configuration>

我的班级:

public partial class AirlineReservation : Form
    {
    public SqlConnection connection;

    public AirlineReservation()
        {
            InitializeComponent();
            string conexiune = ConfigurationManager.AppSettings.Get("connection");
            this.connection = new SqlConnection(@conexiune);
        }
}

当我尝试运行它时,我在此行Keyword not supported: 'initial catolog'.

上得到this.connection = new SqlConnection(@conexiune);

任何sugestions?

1 个答案:

答案 0 :(得分:1)

正确的连接字符串应为:

<add key = "connection" value="Data Source=(local); Initial Catalog = Airline_Reservation; Integrated Security=SSPI"/>

关键字是Initial Catalog而不是Initial Catolog。有关正确连接字符串的更多示例,请参阅以下网站:https://www.connectionstrings.com/sql-server/