SQL Server - An error occurred while executing batch. Error message is: The directory name is invalid
Asked Answered
A

12

45

Our database server had run out of disk space, after freeing up some disk space any query run in sql server management studio, with the results sent to grid view, resulted in this error:
An error occurred while executing batch. Error message is: The directory name is invalid.

When the results sent to text view the queries worked fine.

Does anyone know why this error occurs and how to get rid of it?

Astomatous answered 1/4, 2009 at 10:21 Comment(2)
Login sessions mostly being stuffed up causes this... It a Windows thingRamage
When trying to debug SSMS issues, start ssms with the /log parameter, then open %appdata%\Microsoft\AppEnv\[VERSION]\ActivityLog.xml and search for the error. In my case, searching for "The directory name is invalid" in activitylog.xml found a description containing "InternalGetTempFileName", which hints at the solution several users recommended (i.e., making sure %temp% exists).Beaumont
C
61

All you need to do is to open command prompt and type: mkdir %temp% and press Enter.

Simple as that. No logout/login required.

Coprophilous answered 14/3, 2017 at 15:31 Comment(2)
Worked perfectly!Iolanthe
Thanks for your help. It saved my time :)Swineherd
D
49

Received the message:

SQL Server - An error occurred while executing batch. Error message is: The directory name is invalid

When trying to execute a query in Management Studio after deleting temp files from c:\documents and settings\administrator\local settings\temp

Resolved when logging out of server session and back in again.

This resolution fixes this error on the following environments:

  • Windows Server 2003
  • Windows Server 2008
  • Windows Server 2012
  • Sql Server 2005
  • Sql Server 2008
  • Sql Server 2008 R2
  • Sql Server 2012
  • Sql Server 2014
  • Sql Server 2016
Dosh answered 1/8, 2012 at 12:56 Comment(5)
I had the same issue. Logging out resolved the problem.Whack
Same issue for me, Just Sign out and it will resolve the ProblemCondescending
This worked for me when I experienced this problem after upgrading a remote SQL server from 2012 to 2014.Bunce
Thanks for posting the comment Dragonsdoom. Helpful to know this resolves the issue with later SQL versions.Dosh
c:\documents and settings is not accessible on Windows 2012 and later, I just logged out and in and resolvedOlympe
W
19

I had similar problem on SQL Server 2012. I checked the folder value in %TEMP% variable (echo %TEMP% from command prompt ) and noticed that the folder did not exist. I created the folder and it did the trick!

Weintraub answered 5/3, 2015 at 8:49 Comment(0)
T
12

I had this issue on my webserver (windows server r2 running SQL Server 2012)

The directory name is invalid.
(mscore lib)

Logging out (killing my remote session) and logging back in fixed the issue for me.

Timbal answered 9/6, 2014 at 7:14 Comment(0)
O
5

Is the "Default Location for saving Query Results" set to a valid path in Tools/Options/Query Results/SQL Server/General?

Do the TMP/TEMP environment variables point to valid directories?

Reinstalling the client tools will probably fix the problem.

Overtop answered 1/4, 2009 at 18:4 Comment(2)
I've never run out of disk space and I'm seeing this error and yes to both questions.Cascabel
Did you try cleaning out the temp folder? That worked for me.Proudlove
T
2

I had this same issue on my Windows 7 machine. I actually encountered the error both in SQL Server Management Studio and Visual Studio 2012. I checked my temp directory and found over 66,000 files. Significantly, there were a large number of files called tmpXXXX.tmp where XXXX was a hex number. The problem was that the files went all the way up to tmpFFFF.tmp. So whatever was creating the temp files was not cleaning them up properly and eventually just ran out of files. The solution was to delete all the files in that folder. Not surprisingly, this also greatly improved performance.

The temp folder can be found at: %TEMP% which will be correct for both XP and Win7.

Turne answered 24/10, 2013 at 14:30 Comment(0)
M
1

I was facing this problem for a long time.....simple answer for this problem An error occurred while executing batch. Error message is: The directory name is invalid is just free up the disk drive space ....my problem resloved by this may be this will be helpful for many more...

Maggee answered 24/8, 2012 at 7:7 Comment(0)
I
1

I faced the same problem if DB was created in SQL Server 2008 and it was opened by SQL Server 2005. Just reopen it in 2008.

Irkutsk answered 25/3, 2013 at 11:23 Comment(0)
T
1

I was facing the same problem, so to check this i typed %temp% and it gives an error for folder not found .../temp/2 so i created a folder name 2 inside temp folder and restart the sql server.

which works for me.

Trinatte answered 6/1, 2017 at 4:7 Comment(1)
Mine also has ends with '/2'. I wonder what would be adding that. When I look at the environment variable settings there is no /2 on it so it must be something recently executed. I'm guessing that's why other people fixed this by logging out. That would reset the environment variables for the session.Stancil
S
0

I know it can sound like a joke, but have you tried restarting SQL Server instance?

Steck answered 1/4, 2009 at 10:50 Comment(1)
I personally tried this and it didn't help. Log off/on fixed it though.Cimex
S
0

I solved my problem by running SQL Management Studio as Administrator.

Stout answered 21/6 at 0:2 Comment(0)
T
-2

Yesterday i faced the same error "The directory name is invalid" when i tried to open New Query Window in SQL Management Studio 2014. It happened after cleaning (deleting) %temp% folder files.

I Restarted SQL services but no luck! My problem was solved after restarting the server.

Terpsichore answered 11/6, 2016 at 4:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.