ChatGPT解决这个技术问题 Extra ChatGPT

Management Studio default file save location

Open a new query window. Write some SQL. Save the script, the Save File As dialog box opens - but always to the same default location in the Profiles directory. Is there any way to set my default file location? ...Like I used to do with apps from the 1980s?

Under Tools|Options a default location can be specified for query results. I need the same thing for new queries (the text editor). Tried changing locations in the Registry but SSMS just overwrote my changes. Any suggestions?

(I saw this unanswered question at http://www.eggheadcafe.com/software/aspnet/30098335/management-studio-default.aspx and I had same exact question so I just reposted it here)

in SSMS 2012 the default save location for query results is also used for saving SQL Scripts

P
Phaser Phalanx

This is 5 years old now, but it doesn't mention SSMS version, so I thought I'd add an update for SSMS 2012 and SSMS 2014. Step one differs between the versions, and then the rest is the same:

SSMS 2012

Locate C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Extensions\Application

SSMS 2014

Locate C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\Extensions\Application

SSMS 2016

Locate C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\ManagementStudio\Extensions\Application

SSMS 17

Locate C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Extensions\Application

SSMS 18

Locate C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Extensions\Application

All (continued)

Open ssms.application.pkgdef with text editor(e.g. Notepad) Change the value of DefaultProjectsLocation "DefaultProjectsLocation"="$MyDocuments$\SQL Server Management Studio" For query storage location (query itself, not results), edit this: "DefaultUserFilesFolderRoot"="SQL Server Management Studio" Save the file

Thanks to this source: http://www.networksteve.com/forum/topic.php/How_to_change_the_default_query_save_location_in_SSMS/?TopicId=41425&Posts=0


I am on SSMS 2012, so none of the other "answers" worked. Thanks :)
This was the only non-workaround solution for SSMS 2014 as well.
Thanks D-Money That also worked with SQL management studio 2016
Sql 2016 location C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\Extensions\Application
If your version isn't listed here, you probably just need to look through all the folders 120, 130, etc, starting at the highest number and work your way down, until you find the ssms.application.pkgdef file.. Look in \140, then \130, then \120.. etc, etc.
k
katzbatz

I know this is an old question, but I found a link expaining how to do this properly, at least for SQL 2005. Think it will work for later versions as well.

Changing the my projects folder

The settings are stored in an .vssettings XML file in My Documents\SQL Server Management Studio\Settings folder. Make sure you close SSMS before making changes to this file: SSMS writes to it when you close the application and will overwrite any changes you make. To change the My Projects folder, you are looking for this line:

   <PropertyValue name="ProjectsLocation">%vsspv_user_documents%\My
   Projects</PropertyValue>

The value inside is the location of the My Projects folder. Simply change the value, and the next time you open SSMS the My Projects folder will be mapped.


Note: When trying this out, when I click Save, I still get the original default project folder. But clicking on the 'My Projects' button on the left panel of the save dialog brings me to the folder where I want my scripts saved. Thanks.
H
Hank

A simple work around is to create a shortcut to your desired save location. Place the shortcut in the SSMS\Projects directory. When saving, select "All Files (.)" at the bottom, then double click your shortcut.

Not ideal, but a quick and simple work around.


e
edosoft

Just to make sure, did you update the locations in the registry here:

HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\90\Tools\Shell

HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\90\Tools\Shell\General\ProjectLocationEntries

Thanks! I've been looking for this for a long time too!
Studio resets the values of those reg items when I reopen it.
Yes I have now seen this as well (settings overwritten on restart) I'll look into it.
D
David Guerra

The installation location for SSMS 18 has changed, along with the location of the configuration file that controls the default file save location. The file that needs to be edited is now located at the following path:

C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Extensions\Application\ssms.Application.pkgdef

Close all running instances of SSMS 18. Open ssms.Application.pkgdef with a text editor running with Administrator privileges. Change the value of DefaultProjectsLocation to what you'd like the default to be: "DefaultProjectsLocation"="C:\My\Preferred\Save\Location" Save the file and restart SSMS.


J
John Sansom

As a workaround, you could create new Project of type SQLServerScripts at the location you wish to store the scripts.

Then in the solution explorer just right click the queries folder to create a new script at the location you have specified.

Make sense?

Fore more detailed about Projects and solutions in SQL Server see:

http://msdn.microsoft.com/en-us/library/ms173803.aspx

Cheers,


S
Stephen Turner

An alternative may be to create an NTFS Junction Point.

Grab a copy of the Systinternals Suite, you need the junction.exe from it, and the other stuff is useful.

Run this in the command line:

junction.exe "c:\MyStuff" "c:\Documents and Settings\Stephen.Turner\My Documents\SQL Server Management Studio"

Putting in your My Documents path.

The directory c:\MyStuff will be created and when you browse to it you see all the filess. It's not a copy but a symbolic link, both paths refer to the sames files.


T
Tim Cooper

I had no luck with any of this, my solution is to use a .bat file to create a new empty.sql file and then open it. Then in SSMS , I used 'external tools' to reun the batch. Click it and a new timed stamped .sql file is opened. I use one for each 'project'

create a .bat file

set fName=newQuery%date:~4,2%_%date:~7,2%_%date:~10,4%_%time:~1,1%_%time:~3,2%_%time:~6,2%.sql
copy _queryBlank.sql %fName%

E
Echilon

After searching for this topic for last 3hours, i finally got the way to do this: Changing the My Projects folder location (and other settings) in SSMS


That's the same link as Marshall's answer from 2011 :)
t
td.

the registry changes did not work for me. i just put a shortcut to the network folder I wanted to use in the Mgnt Studio default save path.


B
Brock Adams

This post shows one way.

But, its, registry based, solution still has a gap... When one saves a newly created query (in my SSMS 2008 setup I open it on startup), he has to click "Projects" on the left, as save dialog opens in the standard ...\Documents\SQL Server Management Studio\Projects.


A
AS Mackay

What helped me was editing the registry and Value for DefaultFileOpenLocation

HKEY_USERS\S-1-5-21-1428394981-1396028598-1721912238-1000\Software\Microsoft\SQL Server Management Studio\18.0_IsoShell

Registry Editor screen shot:


I searched for 18.0_IsoShell and changed everything at this level that referred to "%USERPROFILE%\My Documents\" to my "%USERPROFILE%\OneDrive\My Documents" folder. Why does Microsoft make this so hard to change? I shouldn't have to run regedit to fix this!
R
Rafet

In Object Explorer, right-click on your server and click Properties. In the left panel on that Properties page, click the Database settings tab. In Database default locations, view the current default locations for new data files and new log files. To change a default location, enter a new default pathname in the Data or Log field, or click the browse button to find and select a pathname.

NOTE: After changing the default locations, you must stop and start the SQL Server service to complete the change.


M
Michael Schwab

A low tech but quick solution is to simply create a shortcut in the default folder to the one where you want to save your scripts/results/etc.... It's one extra click but involves no messing with settings or the registry.


Ugh, just saw that this solution was already posted above. sorry for the dupe.
P
Pascal Veilleux

The easiest solution for me was to change the folders in the registry (tested with SQL Server 2014)

Make sure to close SQL Server Management Studio before

Launch regedit.exe Browse to Computer\HKEY_CURRENT_USER\Software\Microsoft\SQL Server Management Studio\xx.0 (where xx is your version) Change the different locations path you see in there Start Management Studio and try to open a file, the default directory will be yours

However, the only problem I still have is with the Save... if I create a new Query and save, it still ends up by default under /Documents/SQL Server Management Studio but if you click on the 'SQL Management Studio' link on the left you will go directly into your directory.

https://i.stack.imgur.com/9VGew.png


d
dabend

You can create a symbolic link using mklink.

Delete the existing project folder (copy existing files to preferred location first): rmdir "C:\Users\user\Documents\SQL Server Management Studio\SSMS Projects). Create symlink to your preferred location (example a onedrive folder): mklink /j "C:\Users\user\Documents\SQL Server Management Studio\SSMS Projects" "C:\Users\user\OneDrive - Company\SSMS Projects"

The /j options specifies a hard link that makes it appear as though the file or folder actually exists at that location. When you try to open a file in SSMS the folder should now look like this:

Example Hard Link In SSMS