MSSQL import. mdf. ldf file

Source: Internet
Author: User
Tags microsoft sql server mssql

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.