How To Reconnect Log File To MDF File

If you are a database administrator and facing issues while reconnecting log files to MDF files, read this blog. We have shared some easy ways to reconnect the log file to the MDF file.

Methods to Reconnect Log File to MDF File

Here in this blog, I am going to discuss two simple methods to reconnect SQL Log file to MDF database files. The methods are:

  • SQL Server Management Studio
  • Reconnect Log File without the Transaction File

Let’s explain both methods separately.

SQL Server Management Studio (SSMS) to Reconnect Log File to MDF File

  • Login to your computer and search for SQL Server Management Studio.
  • Connect to the database either by selecting Windows or Server Authentication.

  • Right-click on the Database option and choose Attach. It will lead you to the attached database wizard.
  • Now, click on the Add button.
  • Here, from the list of database files, select the MDF file you wish to connect with the log file and click on the OK button.
  • Click on the message “transaction log file not found” and click OK.
  • Finally, reconnect the Log file to the MDF file whether it is connected properly or not.

This is how you can easily reconnect LDF files with the MDF database files.

Reconnect Log File without the Transaction File

Step 1

Specify the DB name and the .MDF file location using the Create Database with Attach option script given below,

USE [master]
Go
CREATE DATABASE [Tester] ON
(FileName = N’C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\DATA\Tester.mdf’)
For Attach
GO

Step 2

Once the script is executed, a message will display saying a new transaction log file was created.

Thanks!


Similar Articles