We do not recommend migrating SQL Server databases as mdf and ldf files. Even worse, copy them from a running SQL Server.
The preferred option is to backup to one computer and then restore it to another.
If you still want to transfer files, you should follow this sequence:
- Disconnect the database on the machine from which you are copying files. If you simply copy, it is enough to transfer the database to OFFLINE, if you transfer it, you will disconnect the database (detach).
- Transfer files
- On the machine where you are transferring, you attach the database (attach).
It should be borne in mind that the version and release of SQL Server should not be lower than the one from which the files are copied, if the major version is lower, the database will not connect exactly, if the release is lower, it will not connect if there are objects in the database that are available only in more senior release.