Configuring a website to use a hosted database

  1. We need to tell our Web site where to look for its membership database. By default, a connection string named 'LocalSqlServer' is already defined and the web server will try and look in that location. (This is defined in a file called machine.config which resides on the computer/server we are using).
  2. We need to tell the web server:
    1. Not to look in that usual location, and
    2. Where it should look instead.
  3. In order to do that we need to modify the web.config file in our application. The web.config file is an XML document that stores configuration settings for our website.
  4. Directly under the opening tag for the <configuration> section, add a new section named <connectionStrings>, if it does not already exist. Remember that we are working with XML, so ensure you add a corresponding closing tag.
  5. The next step is to remove the reference to the default database (inherited from the machine.config file). Within the connectionStrings section, add the following line of code:
    <remove name="LocalSqlServer"/>
  6. We now need to add a reference to our new database. The example connection string below (taken from the MSDN connection strings example page ) provides the syntax required for a connection string connecting to an instance of SQL server (as you are). You will need to modify the appropriate elements to connect to your individual database.
    <add name="ConnectionStringName"
        providerName="System.Data.SqlClient"
        connectionString="Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=False;User Id=userid;Password=password;MultipleActiveResultSets=True" />
    
    1. Change the name of the connection string to LocalSqlServer (to replace the reference to the one we removed above)
    2. Set the server address, database name, username and password