How to establish a connection to the Northwind database using App.config
and ADO.Net?
How to establish a connection to the Northwind database using App.config
and ADO.Net?
I think this is what you want:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="conn" connectionString="Data Source=.;Initial Catalog=Northwind;IntegratedSecurity=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
Code:
using System.Data.SqlClient;
using System.Configuration;
public class Programa {
public static void Main() {
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
conn.Open();
}
}