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

How cache can be enabled for embeded text as well for search query results in Azure AI ?

 Great question, Rahul! Caching in the context of Azure AI (especially when using **RAG pipelines with Azure OpenAI + Azure AI Search**) can...