Why your development WEB.CONFIG file won't work on a live site
<Amended excerpt from the
Special Report on Going Live on a GoDaddy shared hosting website>
Introduction
This article looks at the details of a web.config file that was created during developing a local website on a PC. It explains why every attribute
of the database connection string needs to change when going live on a shared hosting
site using Microsoft SQL Server.
The Development
Connection String
When you configure a data source in Visual Web Developer Express to connect to your
database, the connection details are stored in the web.config file (unless you specifiy
otherwise). First-time developers may not be aware that in most circumstances, every
attribute will need to be changed when going live on a shared hosting site
using Microsoft SQL Server.
Let's take a look at a web.config file that was created on own PC during development
of a database-driven web application. Right near the top of the file is the connectionStrings
section, which allows your data controls to connect and log into your SQL Express
database. Here is the ConnectionString in full:
<connectionStrings>
<add name = "ConnectionString"
connectionString="Data Source = .\SQLEXPRESS; AttachDBFilename=|DataDirectory|\signup.mdf;
Integrated Security = True; User Instance = True;">
It will help your understanding of the live rollout process if you understand why
the details of the development database connection string won't work in a shared
web-hosting environment that uses SQL Server as the database engine. Let's go through
each item in turn.
Data Source = .\SQLEXPRESS;
This specifies that the database engine is SQL Express, the little brother of SQL
Server. This will have to change when rolling out to a live site using SQL Server.
The format is "Server=<server name>;"
, where you replace the <server name> with the name set up by your host provider.
You use the host's Control Panel to find the server they have assigned to
you, and change the web.config file accordingly.
AttachDBFilename=|DataDirectory|\signup.mdf;
This tells the SQL Express database engine to use the file called signup.mdf in
the \App_Data directory. That's what we called our database. But we have little
or no control over the name of our live database on the shared hosting site. In
fact, we won't know the name until we create the SQL Server database on the live
site, because most hosting sites generate the database name using their own internal
standards. You use the host's Control Panel to find the new database name, and change
the web.config file accordingly.
Integrated Security = True;
If you've used other database applications, you'll have experienced the process
of "logging in" to the application by providing a User ID and password. Visual Web
Developer makes
life easy for us on our PCs and laptops by integrating the database security with Windows user accounts. That's
great for a development PC but won't do in a live web environment. In general, you will need to specify explicitly a
User ID and Password in the web.config
file. Unlike the database name, you are usually
in control of these attributes, as you specify them when creating the new SQL Server
database on your host site.
User Instance = True;
We won't go into the details of user instances here. Suffice it to say that
this option is only for SQLExpress engines, not SQL Server, so it will need to be
removed when rolling out to the live web site.
Conclusion
We've run through each item to demonstrate that going live isn't simply a matter
of copying all files up to the live host site. The solution, if you're wondering,
is to prepare two web.config files - this one for development, and another one to
be used on the production site.
Our Special Report on Going Live
on a GoDaddy shared hosting website walks through the process of creating
the live database and using the information from the host's Control Panel to set
the attributes correctly.
If you're using the Personal Starter Kit, we've put together an
extensive Training Pack with tutorials and video that walks through the process
of Going Live on Go Daddy with
the Personal Starter Kit Training Pack.
Can We Help You Further?
Are you stuck with some aspect of database development with Visual Web Developer
and SQL Express? Finding something difficult to understand? Drop us an email at
"feedback <at> salmon.training.com" and we'll look at turning a solution into
an article for this website.