I am a beginner and learning WPF Application. I have a simple project and in that I want to read DB Configuration string from App.Config File. But I am not able to do so. Below is my attempt:
APP.Config File:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<connectionStrings>
<add name="DBCS" connectionString="Data Source=.\;Initial Catalog=Connect;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
CS Code:
public static void GetDataFromDB()
{
//var CS = @"Data Source=.\;Initial Catalog=Connect;Integrated Security=SSPI";
// ABOVE CODE WORKS FINE
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from tblTenant", con);
DataSet ds = new DataSet();
da.Fill(ds);
}
}
Edit: