Fix – Tempdb path was wrongly updated

You have Moved the tempdb to other drive and forgot to add the name of the MDF and LDF at the end of the file path, hence the error Error: 5123, Severity: 16, State: 1. Also, unable to restart the SQL Server. Don’t be panic. We can fix this.

In this example I’m going to move the tempdb without providing the file names of data and log.

Find the location of the tempdb files

1

you can also use

 select name,physical_name From sys.master_files where database_id = 2 

Let’s move the tempdb to new location without providing the name of the files

ALTER DATABASE TEMPDB MODIFY FILE (NAME = 'TEMPDEV',
FILENAME = 'C:\Tempdb\')
ALTER DATABASE TEMPDB MODIFY FILE (NAME = 'TEMPLOG', FILENAME = 'C:\Tempdb\')

2

Check the file name paths

3

You can see that the tempdb files are modified in system catalog. Let’s restart the sql server service for change to be effected.  I have restarted the service and trying to connect to sql server but it fails.

4.PNG

Event viewer shows

Event 5123

FCB::Open failed: Could not open file C:\Tempdb\ for file number 1.  OS error: 3(The system cannot find the path specified.).

CREATE FILE encountered operating system error 3(The system cannot find the path specified.) while attempting to open or create the physical file ‘C:\Tempdb\’.

So now that we can’t get into SQL Server. How do we fix it?

Go to command prompt and change the directory to sql server instance Binn directory, then type sqlsrvr -c -f

In my machine i have used named instance so the command would be

C:\Program Files\Microsoft SQL Server\MSSQL12.SQL2014\MSSQL\Binn>sqlservr -sSQL2014 -c -f

5.PNG

Now the SQL Server instance is running in single user mode. You can connect to SQL Server.

6.PNG

There you go! you have connected to the instance. Check the path of the tempdb by running the below T-SQL

select name,physical_name From sys.master_files
where database_id = 2;go

7.PNG

You can see in the above screenshot that the physical name was not correctly given. It shows C:\Tempdb. Let us modify the physical path.

ALTER DATABASE tempdb MODIFY FILE (NAME = 'tempdev', FILENAME = 'c:\tempdb\tempdb.mdf')
ALTER DATABASE tempdb MODIFY FILE (NAME = 'templog', FILENAME = 'c:\tempdb\tempdb.ldf')

8.PNG

Here you go! Correct tempdb path.

Once tempdb has been correctly configured , you can close the SQL Server Instance running in the command prompts by pressing Ctrl+C with the window active. Then restart the SQL Service from the sql server configuration manager.

I have restarted the sql server and open the sql server instance normally. There you go! You have fixed the problem.

9.PNG

Note: I have used different parameters

-c : Start as a console application, not as a service.

-m: Start the SQL service in single user mode

-f : Start the SQL service in Minimal configuration mode.

-s : Connect to named instance of sql server

Cheers

Hope you enjoyed the post!

Ramasankar Molleti

LinkedIn: LinkedIn Profile

Twitter: Twitter

Advertisements

About Ramasankar

My name is Ramasankar Molleti, and I have been working on sql server over 10 years, primarily focusing on Database Administration, Architect , Development and Business intelligence of sql server. I also hold various Microsoft certifications (Microsoft Certified Information Technology Professional, Microsoft Certified Technology Specialist, and Microsoft Certified Solution Associate). Disclaimer The views expressed on this website/blog are mine alone and do not reflect the views of my company. All postings on this blog are provided “AS IS” with no warranties, and confers no rights. The owner of https://sqlram.wordpress.com will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.
This entry was posted in Database Administration, TempDB. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s