r/SQLServer • u/Disastrous-Money2395 • Sep 10 '26
Question SSMS 22 error when clicking New Query
I always seem to hit this STG_E_FILEALREADYEXISTS error when clicking "New Query" right after I open SSMS after a reboot where it didn't shut down gracefully and it recovers files. The only way to fix it is to close out any tabs that are named SQLQuery#.sql.
Is there something else I can do to solve this?
4
Upvotes
2
u/ZedGama3 Sep 11 '26
There's a tool that will monitor every system call that you can use to see what it's trying to open. I always get the two confused, but I think it's process monitor, if not then process explorer. It's a pain to filter out the noise, but it's generally good for this kind of thing.
My guess is that there's an existing file wherever SSMS stores it's recovery files and that if you clear those out the problem might go away.
That's my two cents...
4
u/ouchmythumbs Sep 10 '26
I wish they would start including error codes with these messages that we could then search for.
0
u/TrollingForFunsies Sep 11 '26
Do you have any add-ons?
1
u/L0nelyR0gue 29d ago
I too gotten into this problem. Happened after an upgrade to SSMS 22.x
Found that its because the way SSMS is now saving autorecover temp files in %Temp% .
Earlier file name was a random string like 1u5epmb0..sql but this SSMS is saving it as proper "SQLQuery1.sql" and when we open a new window , it is failing. What a nasty bug from such tech giant !?
Can't understand how it even passed their testing !?
1
u/navicat-gu 6d ago
That's the recovered tabs and the new tab fighting over the same temporary name. After a crash, SSMS restores
SQLQuery1.sql,SQLQuery2.sqland so on, then "New Query" tries to create a file with a name that's already in use, and you getSTG_E_FILEALREADYEXISTS.What's helped:
SQLQuery#.sql, there's no collision.If it still happens on 22.12.1, it's worth filing on the SSMS feedback site with the repro, because it's clearly meant to be fixed.
Disclosure: I'm RC, Director of Digital Strategy @ Navicat. Navicat 18 also connects to SQL Server if you ever want a second client, and Navicat Premium Lite is free to try. SSMS is still the right tool here, though.
1
u/Pytzamarama Sep 11 '26
I do not know if of any relevance but I updated to the last SSMS and there were cases that I had 3 or 4 SSMS instances open and it seemed like the generic files like SQLQuery1.sql etc seem to be shared between them! I was doing edits on SQLQuery1 on SSMS1 and SSMS2 later was asking to apply the modifications in its own SQLQuery1 (somewjetre in the AppData/Temp space)
1
u/az987654 Sep 11 '26
Turn off your add ons
1
u/CanProfessional766 Sep 15 '26
Looks like SSMS is getting stuck with the recovered
SQLQuery#.sqlfiles after an improper shutdown. Since closing those tabs fixes it, I’d try clearing the old recovery/temp files and updating SSMS 22. I wouldn’t worry about the database itself this seems to be an SSMS issue