A new public API was added in 8.0 to access the database. It is important that all code accessing the database use this API to create the connection. Reading from the web.config connection strings could result in either an invalid connection or a connection to the wrong database.
PublicApi.DatabaseConnections exposes two methods:
- GetAvailableConnectionNames() returns an enumerable of the connection string names assigned for the current site. The default, and required, connection name for all sites is "SiteSqlServer". There may be additional connection string names, especially for addons such as Analytics.
- GetConnection(connectionName) returns a SqlConnection to the database identified by connectionName. The caller is responsible for managing the connection and ensuring it is properly opened and closed.