Written in front:
Work often encounter the need to move the database to another computer, back up and then lead in it is very troublesome, simply to copy the entire data file in the past.
If copying the. mdf file from the source database is unsuccessful, you must stop the DB instance. Drop to new database path
C:\Program Files (x86) \microsoft SQL Server\mssql10_50.mssqlserver\mssql\data Startup Discovery does not recognize the database.
However, my database configuration opens to discover that the SQL Server service name shows a remote procedure call failure (this is not a problem focus).
Steps:
The first thing to do is to copy the. mdf and. ldf files. I follow the second method below to solve, simple and fast.
How SQL Server Imports Mdf,ldf files _ Baidu Experience
Https://jingyan.baidu.com/article/09ea3ede21258cc0afde3943.html
--Excerpt:
How SQL Server imports the Mdf,ldf file
In peacetime development, often encounter database SQL Server such as import mdf,ldf file problem, below to introduce you how to do, hope to help you.
Tools/Materials
SQL Server
Mdf,ldf file
Method/Step One: Code method
Open SQL Server and you can choose a Windows-mode connection.
Open the database, right-click a database, and select New Query (Q).
Re-code interface to enter the following code, click the F5 key or click the Run button.
The code is as follows:
EXEC sp_attach_db @dbname = ' Your database name ',
@filename1 = ' MDF file path (package prefix name) ',
@filename2 = ' LDF file path (package prefix name) '
You can see that the import was successful. If the import is unsuccessful, you need to modify the permissions of the Mdf,ldf file. Right-click Properties-Security-Edit, Full Control select Allow.
5
This can solve the problem of import, of course, sometimes encounter version incompatibility issues, the lower version cannot import the high version of the SQL MDF and LDF files.
END
Baidu Experience: jingyan.baidu.com
Method/step: Attach Mdf,ldf file directly
1
At the database, right-click Attach to open the additional interface.
2
In the "Attach Database" interface, add MDF files and click "OK".
3
If the import has an error, you can do so with the first method.
Precautions
The second method goes wrong, using the first.
Database to be installed correctly
MSSQL import. mdf. ldf file