Export (0) Print
Expand All

How to: Deploy the ASP.NET Membership Database Without Including User Accounts

This topic describes how to deploy the SQL Server database that is used by default for ASP.NET membership and profile information, without including any user account data (test data) that you have entered on the development computer. The procedures described here assume that you are deploying by using a deployment package and by selecting the Pull data and/or schema from an existing database option on the Package/Publish SQL tab of the project Properties page.

When you select the Pull data and/or schema from an existing database option, you can specify that Visual Studio should deploy only database structures (the Schema Only option) or structures and data (the Schema and Data option). However, if you select Schema Only, the deployed Web site will not work, because the ASP.NET membership and profile system requires configuration data that is stored in one of the membership database tables. On the other hand, if you select Schema and Data, the deployed database will include the user information (test data) that you entered on the development computer.

The simplest way to deploy a membership database without user account data is to create a new database and deploy that database instead of the one that contains test data. The first section of this topic describes how to do this.

Another method is to specify the Schema Only option and then add a custom script that inserts data in the table that requires configuration data. This method can be a better choice if you have customized the membership database (for example, by adding tables to it). The second section of this topic describes how to do this.

This topic does not contain detailed database deployment instructions. It is intended to supplement the topic How to: Deploy a Database With a Web Application Project.

NoteNote

If you have already deployed the database by using the Schema and Data option and you want to redeploy in order to eliminate test data that was unintentionally deployed, you have to specify that existing tables should be dropped before being re-created. For information about how to do this, see the Redeploying by Using Automatically Generated Scripts section in How to: Deploy a Database With a Web Application Project.

In the following procedure, you create a new membership database and copy the resulting .mdf file into the App_Data folder of the project to deploy. When you use one-click publish or when you deploy by using a Web deployment package, that database is then used as the source database for generating deployment scripts.

To deploy an ASP.NET membership database that has not been customized

  1. Create a new Web application project by using the ASP.NET Web Application template.

  2. In Solution Explorer, expand the Account folder, right-click the Login.aspx file, and then click View in Browser.

  3. Enter any user name and password, and then click the Log In button.

    When ASP.NET attempts to validate the credentials that you enter, it creates the aspnetdb.mdf database file. This results in a membership database that is empty except for the required configuration information.

  4. Copy the aspnetdb.mdf database file from the new project's App_Data folder to the App_Data folder of the project that you want to deploy.

    This overwrites the existing membership database and eliminates all the user information except for the information that you created in the preceding step.

  5. On the Package/Publish SQL tab, select Schema and Data under Database scripting options.

In the following procedure, you use automatic scripting to deploy only the database structure, and you create a custom script to populate only selected database tables.

To deploy a customized ASP.NET membership database

  1. Run Web Deploy to create deployment scripts by entering the following command at a command-line prompt:

    "C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe" -verb:sync -source:dbfullsql="[your connection string]" -dest:dbfullsql="c:\temp\InsertIntoAspNetDB.sql"

    If the connection string contains the string "|DataDirectory|\aspnetdb.mdf", replace "|DataDirectory|" with the full path to the App_Data folder.

    If the Program Files folder is on a different drive, substitute the appropriate drive letter. You can select a different temporary folder and file name for the output .sql file.

  2. In the generated .sql file, delete everything except Insert statements for the aspnet_SchemaVersions table and for any custom tables that you want to deploy data for.

  3. On the Package/Publish SQL tab, select Schema Only under Database scripting options, and add the edited .sql file as a custom script.

Community Additions

Show:
© 2014 Microsoft