[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
When you publish a Web application project by using One-Click Publish, you can use Visual Studio 2010 to include any dependencies that the application has on SQL Server databases. As part of the publishing process, you provide the connection string for your source database. When you publish, creates SQL scripts for the database schema and optionally for the data, and then publishes these with your Web application.
You can also provide custom SQL scripts and specify the sequence in which they should run on the deployment server. At deployment time, you provide a connection string that is appropriate for the target server. The deployment process then uses this connection string to run the scripts that create the database schema and add the data.
This walkthrough shows you how to do the following:
Create a Web application project.
Specify a database to include when the Web application is published.
Create a publish profile.
Publish a Web application by using One-Click Publish.
In order to run this walkthrough, you will need the following:
Web publishing does not work for Web application projects that were created by using earlier versions of Visual Studio. To publish a Web application project that was created in an earlier version of Visual Studio, back up the existing project, and then open the project in Visual Studio 2010. You will then be prompted to convert the project to a Visual Studio 2010 project.
Creating a Web Application and Database to Deploy
To begin, you will create a Web application project that you can publish.
To create a new Web application project and database to publish
Select Project from the File menu.
The New Project dialog box is displayed.
Select the Web node and then select ASP.NET Web Application from the Visual Studio installed templates section.
Visual Studio creates the Web application project.
Right-click the App_Data folder, select Add, and then select New Item.
The Add New Item dialog box is displayed.
In the Categories list, select Data.
In the templates window, select SQL Server Database.
Enter a name for the database, and then click Add.
An empty database is created in the App_Data folder.
Specifying the Database to Include When You Publish
The next step is to specify scripts that are associated with the database. You use the project's Properties window to specify the database and any scripts associated with the database.
The following illustration shows the Publish - SQL tab that is used to specify a database to be included when Web publishing.
The Publish - SQL tab of the Properties window
.png)
To specify a database using the Properties window
Double click the Properties folder.
In the Properties window, select the Publish - SQL tab.
In the Configuration list, select the Debug configuration setting.
Click Add Data Connection.
Enter a name to identify the database in the Connection Name field.
New fields are shown when you complete the name of the connection string.
Select the Automatically script database check box.
Directly under the check box, click the ellipsis button (…) that is next to the Connection String field in the Source section.
In the Source Connection String dialog box, type (local) in the Server name field.
In the Log on to the server section, click Use Windows Authentication.
In the Connect to database section, select Select or enter a database name and enter the name of the database you created.
If you did not rename the database, the default name of the database that you created is Database1.mdf.
Click OK.
On the Properties page, in the Source section, click Schema only.
At the bottom of the window in the Destination section, click the ellipsis button (…) button that is next to the Connection String field.
In the Destination Connection String dialog box, enter the server name and logon credentials of the database server where you want to deploy the database.
If you are deploying to a hosted server, a connection string is typically provided to you by the hoster. If you are deploying to a local server, the database administrator typically provides you with the connection string.
Click OK.
The connection string appears in the Connection String field.
Save the Properties page settings.
Creating a Publish Profile
While you create a Web application, you can create Publish profiles that is associated with that application. Publish profiles enable you to save logon credentials and Web application settings when you publish a Web application to an IIS server. You can create profiles for any number of deployment scenarios, including test, staging, and production servers.
For this walkthrough, you will create a Publish profile for the host Web server that you intend to use to run your Web application. Because you are entering logon credentials, each profile that you create will be unique to the server that it is created for.
To create a new Publish profile
Right click the project name in the Select Solution Explorer window.
Select Publish….
The Publish Web dialog box is displayed.
.png)
In the Publish Profile text box, enter a name for the profile.
It is recommended that you use a name that indicates the purpose or location where the profile is used, such as TestServer or DiscASPServer.
In the Publish Method list, select MSDeploy Publish.
This is the recommended selection when you deploy a Web application project.
Enter the Service URL, such as https://MyServer:8172/MSDeploy.axd.
This information is typically provided by a server administrator or the hosting company.
Enter the application name in the Site/Application field, such as MyDomain.com/MyApplication.
Select the Mark as IIS application on destination check box.
This causes the application to be marked as an IIS application on the destination server.
Select the Do not delete extra files on destination check box.
If you do not select this check box, all files on the IIS Server under your application are deleted before they are published.
Enter the user name and password that you use to access the account on the targeted server.
This information is typically provided by the server administrator or hosting company.
Click Publish.
The Publish Web dialog box closes.
Publishing a Web Application and the SQL Database Using the One-Click Toolbar
After a Publish profile has been created, you can select that profile to publish a Web application from the One-Click Publish toolbar.
Note |
|---|
If you publish using the MSDeploy Publish option, only files that have changed since the last time the application was published are updated. |
To use the One-Click toolbar to publish a Web application
From the main menu, select View, select Toolbars…, and then select Web One-Click Publish if it is not already checked.
You can also enable the One-Click toolbar by right-clicking the main menu and selecting Web One-Click Publish.
Select a publishing profile from the drop-down list on the One-Click toolbar.
.png)
Click the Publish Web button to publish the Web application project and the SQL database by using the profile you selected.
Concepts