To connect an ASP.NET application to a database, the connection string is stored in the web.config file. This connection string contains the name and actual connection data to identify and connect to the database. Within the application, classes like SqlCommand, SqlConnection, and SqlDataReader/SqlDataAdapter are used to interact with the database by executing queries or stored procedures and retrieving result sets. Data retrieved from the database is stored in a DataSet object containing DataTable objects that can then be accessed like database tables.