Monday, May 3, 2010

how to read connection string from app.config file in window application

how to read connection string from app.config file in window application

there is a requirement that we need to read some key values in our window application from app config file
for example we need to read connection string from app config file


this is our app.config file






connectionString="Data Source=localhost;Initial Catalog=database name;User ID=sa;Password=123456"
providerName="System.Data.SqlClient" />






so for read this we have to make a method



public string connection()
{
return System.Configuration.ConfigurationManager.ConnectionStrings["pollsConnectionString"].ToString();
}




but in this you might get error is that ConfigurationManager doesnt exists in this context
so remove this simply add system.configuration namespace
but if error still exists add reference of configuration manager

No comments:

Post a Comment

.net core

 Sure, here are 50 .NET Core architect interview questions along with answers: 1. **What is .NET Core, and how does it differ from the tradi...