its a very old post, but I needed this as well.
I knew I made quite a big query earlier today, and I forgot to save it and when I came back to my PC, I saw it shut of by my soon.
I've been looking for a while, but finally found a solution. Here are the steps to find any "lost" query (.sql) that was made use Sql Server Management Studio, in the past 7 days (default). It can be increased to 30.
I did not found the path on which my "unsaved queries" were stored my SSMS. So I did the following:
Open SSMS
Goto Environment > Autorecover, set it to 1 minute and 30 days. Ok & close
Create a new query, select * from dbName.scheme.tablename, and wait 1 minute (or the time that is in the auto recover
Force close the SSMS.exe by ending the task, or killing the ssms.exe process via task manager
Relaunch SSMS as usual, and u should get a popup asking you to recover your previous query/queries. (--> SSMS AutoRecover SCreenshot)
Here you can see the path on which SSMS stores the "autorecover" files. In my case it was
C:\Users\Admin\AppData\Local\Microsoft\SSMS\BackupFiles\Solution1
Open this folder in windows explorer, and you see all kinds of recovered-monthname-day-year-xxxx.sql files.
If you dont wont to open all sql files 1 by 1, to see which is the query you need, use a tool like notepad++ or even SSMS it self, using CTRL + F, and search in files. Specify the directory from above, and search a tablename or something specific you remember using in the query you are searching for
Enjoy ! <3