I am creating an application for the database given ms sql server. The connection string is in the app.config configuration file, I want to bring the methods of working with the database into a separate class, then to access it in the handlers for buttons and events in the application.

Please tell me what this class might look like and how to access the configuration file from it to read the connection string! If possible by example, it is very necessary!

The configuration file looks like this:

<?xml version="1.0"?> <configuration> <connectionStrings> <add name="TestConnectionString" connectionString="Data Source=.\sqlexpress;Initial Catalog=TestDatabase;Integrated Security=True;" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration> 
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

 var connection = System.Configuration.ConfigurationManager.ConnectionStrings["Test"].ConnectionString; 
  • thank! and how the class with methods of work with a database can look? I can't find it - Wind
  • May look different. It all depends on your task - Atlantis
  • If I indicated the correct answer - tick it off. Indicate that this is the correct answer. - Atlantis