
Deploying a SQL Server Express Edition Database
A SQL Server Express Edition database is made up of two files: the .mdf file, which contains the database schema and data; and the .ldf file, which contains log information for the database. If you are making a file-based connection to your SQL Server Express Edition database, these files can be copied with your application to a target server using XCopy, FTP, or another means. Your application will continue to run as long as the SQL Server Express Edition is installed on the target server.
Because SQL Server Express Edition uses the same file format as other versions of SQL Server 2005, you can copy the .mdf and .ldf files to a server running SQL Server and then attach the files as a database.
注意: |
| If you are deploying your SQL Server Express Edition database to a Web server that hosts multiple sites that do not trust each other, then you cannot use file-based connections or user instances to help ensure that your data is not exposed to other applications on the server. In this case, it is recommended that you migrate the contents your SQL Server Express Edition database to another version of SQL Server 2005 that your deployed ASP.NET application can access. |
If you want to copy an empty SQL Server Express Edition database that contains a database schema, but no data, the SQL Server management tools enable you to generate scripts that can be run in your target database to duplicate the schema from your development database.
If your SQL Server Express Edition database contains encrypted information, such as encrypted passwords stored in a membership database, make sure that your encryption keys are copied to the target server as well.
If you want to move the entire SQL Server Express Edition database, you need to ensure that there are no open connections to the database that would cause it to be locked.
Unlocking a Locked Database
If there is an open connection to a database, the database is locked and cannot be moved or deleted. Open connections can be held by an ASP.NET application, a designer such as Visual Studio, or some other program or database client. To unlock a database, all open connections to the database must be closed. You can close the open connections in the following ways:
-
You can close the connection held by a designer by exiting the program. (In Visual Studio, you can right-click the database in Solution Explorer and select the Detach option; or you can right-click the database in Server Explorer and select the Close Connection option.)
-
You can close any connections held by an ASP.NET application by ending the application. This can be done by using IIS Manager, or by placing a file named App_offline.htm in the root directory of the ASP.NET application (you must remove this file to restart the application).
-
You can close any connections held by other sources, such as a Windows Forms application, by exiting the program.