Winform添加App.config文件,和调用连接字符串的两种写法

1.App.config文件写法

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="conn" value="Data Source=.\sqlexpress;Initial Catalog=School;Integrated Security=True"/>
</appSettings>
</configuration>

调用如下:

public static string connStr = ConfigurationManager.AppSettings["conn"].ToString();


2.App.config文件写法

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="TrackingDatabase" connectionString="Data Source=127.0.0.1;Initial Catalog=WorkflowTracking;User ID=sa;Password=123" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>

调用如下:

String conn = ConfigurationManager.ConnectionStrings["TrackingDatabase"].ConnectionString.ToString();

你可能感兴趣的:(WinForm)