You cannot safely do a plain copy of SQL Server database files when that database is open and in use by SQL Server. For this reason, these files are typically opened by SQL Server disallowing any sharing, even shared reads. There is an access privilege that can bypass even this, but I do not recommend it as the copied files will likely be corrupt and unusable.
Many (most?) BACKUP tools and products can safely copy these files, but this is because they use a special SQL Server interface and/or interlock to insure that they do not get files that are corrupted by SQL Server changing the contents midway through a copy.
So the solutions to this problem are either:
- Shutdown SQL Server (or detach the specific database) before you run your XCopy (then re-Attach the database when done), or
- Use a Backup tool that supports SQL Server instead, or
- Use SQL Server BACKUP commands to make backups of the databases and log files and then have your XCopy copy only the backup files, not the live files, or
- Just have SQL Server BACKUP do all of the work without any XCopy. SQL Server has a lot of facilities to support this approach and it is was most DBAs do for this kind of thing (these facilities using SQL Agent to run a Powershell job calling SQL Backup).