If you want to keep your Web application on a hosting site, you need to make the pages available on the hosting site. You also need to create, and if appropriate, populate your application’s database tables on the hosting site. Copying the pages is the easy part, so let’s start with that task.
To make your Web pages accessible on the hosting site, you need to copy the pages from your computer to the hosting site’s server. I can’t give you exact instructions for copying Web pages to your hosting site, because each site runs differently. Instead, I’ll provide general instructions that work for most hosting sites and hope that you can extrapolate to fit the circumstances of your hosting site. The most fundamental assumption I’ll make is that your hosting site allows you to transfer files to its server using File Transfer Protocol (FTP). I assume this because FTP is the most common way to copy files to a server. If your hosting site doesn’t support FTP, you’ll need to follow the instructions that your hosting site recommends. In that case, the instructions in this section for copying files won’t apply to you. However, the section “Copying Database Tables to a Hosting Site” later in this appendix might still apply.
When you signed up for hosting services, your hosting site administrator sent you information that you need for connecting to the hosting server and transferring files. The information you need is the name of the hosting site’s FTP server, the
With the information I listed in hand, you’re ready to connect and copy files. You might already have an FTP client program that you’re used to
Figure B-2:
Connecting to a hosting site using a popular FTP client program.
If you don’t have an FTP client program, you can take advantage of the support in Web Matrix for FTP. Right-click
Figure B-3:
Creating a new FTP workspace in Web Matrix.
Web Matrix displays the New FTP Connection dialog box, where you can enter the FTP connection provided by the hosting site administrator, as shown in Figure B-4.
Figure B-4:
Connecting to an FTP server in Web Matrix.
After you click OK, Web Matrix connects to the FTP site and displays the files from the site in the Workspace window. From this point, you can work with the pages as if they were on your local computer—you can open, create, and delete them. For example, you can
You can copy files from your local hard disk to the FTP site as well. In the Workspace window, open the node for the drive where your Web pages are located, and then just drag the pages from that node to the node for your FTP server. Web Matrix automatically copies the files.
| Tip |
You can create a top-level node in Web Matrix’s Workspace window for the folder where your Web pages are located, which makes it easier to copy the pages to the FTP server. |
It’s relatively easy to copy files to your hosting site. Copying database information, however, is more involved. Let’s tackle that
If you want to run
| Note |
Even if you have SQL Server installed on your computer, Web pages on another site (such as the hosting site) can’t access your SQL Server across the Web. Web pages need to be able to connect to a SQL Server that’s on the same local area network (LAN) or the same computer as the Web server. |
You can’t copy tables from MSDE or SQL Server on your computer directly to SQL Server on the host computer. SQL Server data isn’t stored in a format that allows you to copy it as an individual file. Deploying the data tables from your Web application is therefore an indirect process. In effect, you must follow these steps:
Determine the structure (schema) of the tables in your WebMatrix database application.
Export the data from your local MSDE tables into a format that you can copy to the hosting site’s server.
Re-create the same tables on the hosting site’s SQL Server according to the schema you determined in step 1.
On the hosting site, import the data from the exported files into the hosting site’s SQL Server.
Change connection strings in any data-access pages in your application to the connection string provided by your hosting site administrator.
Although you might be able to perform the export side of these
ExportTable.aspx
page and the
ImportTable.aspx
. You run the page on your local computer. The export page reads the schema of an MSDE table, creates a SQL
CREATE TABLE
statement that matches the structure of the MSDE table, and then stores the SQL statement in a .schema file. The page reads the data out of the table and creates an XML file out of the data.
You then copy the schema and XML files to the hosting site server, along with the page. Using your browser, you request the
ImportTable.aspx
file from the hosting site. You can then specify a file to import. The page re-creates the table in the hosting site’s SQL Server, and if you want, reads the data from the XML file into the new table. Figure B-5 illustrates how the export and import process works.
Figure B-5:
Transferring MSDE data to the hosting site via text files.
The following procedure describes how to export a table from MSDE.
Export a table from MSDE
From the ASP.NET Utilities folder on the companion CD, copy the
ExportTable.aspx
file to C:\WebMatrix or to the folder where you keep your Web pages.
Run the page. You can open the file in Web Matrix and run it, or if you can run pages using IIS, you can simply request the page in your browser. The page looks like the following:
Enter the instance name for your copy of MSDE, and enter the name of your database. (If you followed the recommendation in the book, your database is named WebMatrix.) When you’ve entered the two values, click Get Tables. The page fills the drop-down list with the
Select a table, and then click View SQL Statement. The page displays a SQL CREATE TABLE statement that corresponds to the structure of the table that you selected.
Examine the CREATE TABLE statement, and if you want, edit it.
Click the Export button.
Web Matrix creates two files based on the selected table name. The .schema file contains the
CREATE TABLE
statement that was displayed in the text box. The .xml file contains the data (if any) from the table. For example, if you selected the Calendar table, the
ExportTable.aspx
page creates the Calendar.schema file and the Calendar.xml file.
The two files you just created contain the information required to re-create the original table on the hosting site’s SQL Server. You’re then ready to import the table into the hosting site’s SQL Server.
Import a table into a hosting site’s SQL Server
Make sure you know the connection string that your hosting site administrator has prepared for you. If you don’t have a connection string, contact the hosting site administrator.
Using the technique you usually
Copy the
ImportTable.aspx
file to the hosting site as well. You can find the
ImportTable.aspx
file in the ASP.NET Utilities folder on the companion CD.
Run the
ImportTable.aspx
file in your browser, using the URL of your hosting site. The page looks like the following:
Enter or paste the connection string into the page.
Select a table from the drop-down list. The list contains the names of tables for which you have
Click Create Table to create the table using the SQL statement in the .schema file. If the process results in an error, study the error message
If you want to import data into the new table, click the Import Data From XML File button. The page reads the data in the .xml file and creates new records in the selected table in the hosting site’s SQL Server.
| Note |
The Import Table.aspx page does not check whether the table contains any data. Importing data into a table with existing data can have different results, depending on the table. If the table uses an auto-increment primary key, importing data can result in duplicate records. If the table doesn’t use an auto-increment primary key, the import process might generate an error indicating that a primary-key violation has occurred. |
If all goes well, you’ll be able to use the
ExportTable.aspx
and
ImportTable.aspx
pages to move your MSDE data to the hosting site’s SQL Server. The final step in moving your data tables to the hosting site is to edit any Web pages in your application that involve data access and to change the connection string in the page. When you built the Web pages on your computer to access MSDE on your computer, Web Matrix embedded a connection string (or more than one) into the page. After you copy a Web page to a hosting site, however, any connection strings in the page won’t be valid any more, so you need to substitute the connection string provided by the hosting site administrator.
Editing connection strings in your data-access pages isn’t difficult, but it’s a little
|
Page |
Chapter |
Connection string location |
|---|---|---|
|
|
13 |
AddSlide function (code) SqlDataSourceControl , ConnectionString property |
|
|
14 |
InsertCalendar function (code) |
|
|
13 |
InsertSlideshow function (code) SqlDataSourceControl , ConnectionString property |
|
|
9 |
SqlDataSourceControl , ConnectionString property |
|
Guestboo.aspx |
10 |
AddGuestBookEntry function (code) |
|
|
15 |
AddGuestbookEntry function (code) |
|
|
12 |
SqlDataSourceControl , ConnectionString property |
|
|
12 |
GetSlides function (code) |
|
|
14 |
GetAppointments function (code) SqlDataSourceControl , ConnectionString property |
|
|
10 |
SqlDataSourceControl , ConnectionString property |
|
|
11 |
SqlDataSourceControl , ConnectionString property |
|
ViewGuestbookList_Repeater. aspx |
11 |
SqlDataSourceControl , ConnectionString property |
|
|
In this book, I’ve been careful to alert you to potential security issues that can arise in the code on your Web pages or in the administration of your Web site. The export and import pages that I describe in this appendix can represent a major security risk on your site. In effect, the pages provide direct access to the database server for your application. Because the export and import processes represent such a security vulnerability to your application, you must use them with extreme caution. In general, don’t allow
ExportTable.aspx
or
ImportTable.aspx
pages at all. The safest practice is to use the pages one time to export the data from MSDE and import it into the hosting site’s SQL Server, and then to remove both pages from the site immediately. Likewise, as soon as you’ve imported data into the hosting site’s SQL Server, delete the .schema and .xml files that you copied to the hosting site before importing.
Because you should use the import and export pages only within a secure context, the pages
ExportTable.aspx
page, the
textSqlStatement
control allows you to edit a raw SQL statement and does not prevent you from entering a
I made these design choices because the export and import pages are designed to be used by a trusted user—namely, you, the Web site owner. For example, I pass error message information through from MSDE and SQL Server because while working with these pages it’s important that you see the details of any errors that occur during the export or import process. Similarly, I allow you to edit the SQL statement in the
ExportTable.aspx
page because it gives you a level of control over the SQL statement that might be necessary for you to import data on the hosting site successfully.
In general, you should work with the export and import pages as you would with any administrative-level utility. Use them carefully, and don’t let
|
|