SQL SERVER – Error : Fix : Msg 5133, Level 16, State 1, Line 2 Directory lookup for the file failed with the operating system error 2(The system cannot find the file specified.)

I recently got email from friend who had suffered from following error.

Msg 5133, Level 16, State 1, Line 2
Directory lookup for the file “filepath” failed with the operating system error 2(The system cannot find the file specified.).
Msg 1802, Level 16, State 1, Line 2
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
Msg 5133, Level 16, State 1, Line 2
Directory lookup for the file “filepath” failed with the operating system error 2(The system cannot find the file specified.).
Msg 1802, Level 16, State 1, Line 2
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

As per him he had gone crazy to find solution. He had been trying to create database  and he had all the admin privileges. After getting remote desktop, I realize that he was everything correct but the filepath he was trying to create. Once he corrected the filepath everything was smooth from there.

If you have the same error I suggest you carefully check your filepath. There must be some typo or error in filepath. If that is not the case and with admin rights you are still facing issue, post a comment here.

Reference: Pinal Dave (https://blog.sqlauthority.com)

SQL Error Messages
Previous Post
SQL SERVER – Find Total Number of Transactions on Interval
Next Post
SQL SERVER – Quickest Way to Identify Blocking Query and Resolution – Dirty Solution

Related Posts

37 Comments. Leave new

  • Most of the time people use local system’s path and not the server’s path which leads to this error

    Reply
  • This is like “check that the device is plugged in”. Nothing to blog about.

    Reply
  • I already get this error and the paths were right. I was trying to create database in a path like this: C:\programs\MyProgram\MyProgram.mdb and what solves my problem was runnig sql server not by local account but by using a computer account. Is this the macthing of the admin privileges??
    Reagards.

    Reply
  • GodsMessenger
    July 12, 2011 1:07 am

    Check the service account SQL Server is running on. If it is using Network Services, change it to Local System or windows admin account.

    Reply
  • verify that you created the folders in the path
    verify that your session runs by windows authentication or damain account that had permission on created Folders

    Reply
  • As above: permission error on folder, not incorrect path

    Reply
  • Msg 5133, Level 16, State 1, Line 2
    Directory lookup for the file “filepath” failed with the operating system error 2(The system cannot find the file specified.).
    am getting the same error msg ihave tried to run in Admin mode also, i have check my file path everything is good, But still am getting this error. can you tell me why?

    Reply
  • FIX: I was importing a .BAK file from Microsoft SQL Server Management Studio Express and kept getting the error: Directory lookup for the file “C:\MSSQLDB\mydatabase.mdf” failed with the operating system error 2.

    This was regardless of the fact that I was importing the .BAK file from a completely different location!

    After not having any luck with more logical solutions…I tried creating a ”C:\MSSQLDB” folder and moving my BAK file into that folder. (folder didn’t exist before)

    This ended up working and my database imported successfully.

    Reply
  • Msg 5133, Level 16, State 1, Line 2
    Directory lookup for the file “E:\db_SqlDatafiles\Trustbank_VMUCB_Warora1.ldf” failed with the operating system error 2(The system cannot find the file specified.).
    Msg 3156, Level 16, State 3, Line 2
    File ‘Trustbank_Hinganghat_Branch_log1’ cannot be restored to ‘E:\db_SqlDatafiles\Trustbank_VMUCB_Warora1.ldf’. Use WITH MOVE to identify a valid location for the file.
    Msg 3119, Level 16, State 1, Line 2
    Problems were identified while planning for the RESTORE statement. Previous messages provide details.
    Msg 3013, Level 16, State 1, Line 2
    RESTORE DATABASE is terminating abnormally.

    Reply
  • Directory lookup for the file “E:\SQLDATA\DATA\HMS_DB_OOCE.mdf” failed with the operating system error 3(The system cannot find the path specified.).

    I got this error when trying to execute script from one system in another system.

    Reply
  • Spot on!! Thank you Pianldave!!!

    Reply
  • Also, check if you have directly opened the file you have been given ?
    Better idea is to create a ‘New Query’ window on the ‘master’ then copy paste the script and then execute

    Reply
  • Mark Sinnathamby
    August 15, 2013 8:34 pm

    I got this same problem, but after I manually created the folder structure i specified in the FileName, and then ran the create database script again, it ran successfully without throwing this error.

    Reply
  • hello sir i have this error,
    “Msg 5120, Niveau 16, État 101, Ligne 1
    Impossible d’ouvrir le fichier physique “D:\WebSites\VentePC\App_Data\VentePC.mdf”. Erreur du système d’exploitation 5 : “5(Accès refusé.)”.
    I changed the file path but I always have the same error. Please help me.

    Reply
  • This site is top notch!

    However, this answer does not (exactly) apply to all situations. I got this error today using a script that does not name a path. It uses the storage location set in the instance preferences.

    This same script has been used many times (100’s) and has been used between these same two servers at least 10+ times.

    One of the other commenters said something about the SQL user, that could be, but why would it change all of a sudden?

    Furthermore, the the source system datastore was on the “D:” drive the target system has no “D:” drive… — but I do see the bad path (“D:…”) in the error, why is this showing up at all, it is a full backup.

    Reply
  • im not able to provide the path , i have to copy the path the path and paste it in the file name still i have this error ..the mdf file is in the ‘owner’ folder even after providing full control i am not able to access the files within it..

    Reply
  • For me it worked when I set full permissions on Authenticated users. Before that, I wasn’t even able to see folders in the folder structure withing sql server when picking path to DB.

    Reply
  • i have this problem can any one help me pls thank you in advance
    Msg 3202, Level 16, State 1, Line 1
    Write on “H:\xxx.BAK” failed: 2(The system cannot find the file specified.)
    Msg 3013, Level 16, State 1, Line 1
    BACKUP DATABASE is terminating abnormally.

    Reply
  • Hi,
    I have a problem for a week and I can not solve it on my sql 2008 r2.
    I have a backup plan that saves my database that no longer works however it is in place for more than 3 years. Here is the error returned:
    Msg 3201, Level 16, State 1, Line 1
    Can not open backup device
    ‘\\SNAS\SauvSQL\X3\master_backup_2015_01_23_111742_8108206.bak’.
    Error 5 (Access is denied.) Of the operating system.
    No setup changes were made on my SQL server and my storage server.
    I checked the rights and local backup works.
    Can you help me ?

    Reply
    • Access denied means that SQL Service account is not having permission. There must have been a change – may not be by you but may be by domain policy?

      Reply
  • Curiosly I am having this issue and no clue how to fix it, but my situation is sligthly different. I am creating a DB on NAS drives (one drive for Data and another one for Log), they are visible from the OS (Windows Explorer) I have the permissions, I am logged with a domain account, SQL Service is running on another domain account and both accounts have FULL permissions over the drives. But the command does not work and returns this error, also the SQL Server Management Studio does not display my NAS drives… What am I missing?

    Reply
    • 1. What’s the error you are getting?
      2. How do you access them in Windows Explorer? Mapped drive?
      3. What’s the version of SQL?

      Reply
      • Thanks for your reply Dave, the error is the one refered in this post ‘Msg 5133, Level 16, State 1, Line 1. Directory lookup for the file “G:\Test\NAS_Test.mdf” failed with the operating system error 3(The system cannot find the path specified.).’
        In Windows Explorer the devices are as you say mapped drives. The versión of SQL Server is 2012. I have tested creating new files and folders on the devices from Windows Explorer and it works fine, so the permissions are not an issue. Anything else tan can help to diagnose the issue?

      • SQL Server is a separate process which may not be aware about the mapped drives on the operating system. You need to use XP_CMDSHELL ‘Dir G:’ command to check for the drives are visible to SQL Server.

      • Thanks Dave, I will have to check why this is happening, because I ran the command (first I had to enable it) and the result is an error indicating ‘The system cannot find the path specified’.

Leave a ReplyCancel reply

Exit mobile version