
How Do I Use Xcopy Deployment?
When an application first establishes a connection from a running instance of SQL Server Express, SQL Server Express will automatically attach an .mdf file. When the user closes the application, SQL Server Express detaches the .mdf file from the instance. The Xcopy feature causes the .mdf file to be fully portable. You can copy and move the file and, at the same time, run multiple copies of the file on the same instance.
Logical Database Naming
When SQL Server Express attaches a database, it automatically generates a logical name for the database, unless the connection string in your application specifies a logical name. This logical name must be unique. SQL Server Express will use the drive letter, directory name, and database file name as the logical name. For example, if your .mdf file is in the C:\Program Files\My Application\Data\MainData.mdf path, SQL Server Express will assign a logical database name that exactly matches the path:C:\Program Files\My Application\Data\MainData.mdf.
Note: |
|---|
|
If the length of the full path and file name exceeds 127 characters, the logical database name is shortened and prefixed with a GUID. This guarantees a unique logical name.
|
Log File Creation and Naming
When you deploy your application, you should include in the Xcopy only the application files and the .mdf file. You should not include the log file (.ldf). SQL Server Express will automatically create a new log file when it attaches the database. SQL Server Express will name the log file database_name_log.ldf. If a file that has the same name already exists in the same directory as the .mdf file, the existing file is used.
Limitations when Using Xcopy Deployment
When you use Xcopy deployment with your application, some SQL Server Express features might not function as expected. The following list describes limitations that might occur.
-
Any Transact-SQL code that contains logical database names will not work.
Because the logical name of the database depends on the file location, which will change with each Xcopy, any code that specifies a logical database name will fail.
-
Replication scenarios do not work.
Replication requires a persistent logical database name. If your application uses replication, you should not use Xcopy deployment.