ChatGPT解决这个技术问题 Extra ChatGPT

How to remove "Server name" items from history of SQL Server Management Studio

When trying to connect to a server in Management Studio (specifically 2008), there is a field where you enter the Server name. That field also has a drop-down list where it shows a history of servers that you have attempted to connect to.

How to remove an individual item from that history? How to remove an item from the Login field history for each Server name?

See my answer for a little UI I wrote to do this, I was a little late to the party so my answer is way down the bottom at present.
Naughty. Next time use incognito mode if you're going to query any dodgy databases.
Install Everything tool , then search the file mru.dat and delete it

A
Aaron Bertrand

As of SQL Server 2012 you no longer have to go through the hassle of deleting the bin file (which causes other side effects). You should be able to press the delete key within the MRU list of the Server Name dropdown in the Connect to Server dialog. This is documented in this Connect item and this blog post.

Note that if you have multiple entries for a single server name (e.g. one with Windows and one with SQL Auth), you won't be able to tell which one you're deleting.


With SSMS 11.0.3128.0 this does not work. Did it get nixed because the behavior led to poor UX?
@JoeBrockhaus Works with 11.0.5058.0. Just open the drop down, move the selection over the name you want deleted, and press the Delete key. If you have multiple entries you can select the entry so the ComboBox closes, check that it is the one you want, then hit the open button on the ComboBox and press delete (the currently selected entry will be deleted).
Seriously? Why didn't I try that first? Haha. For anyone interested, I can confirm this works in SSMS 2014.
Works on 2016 as well. Thank you! I had an incorrect cached username and this fixed it.
Not sure how I feel about the "pointing the cursor" to select the target of the Delete key, but thanks, it works.
H
Hardik

Here is simpliest way to clear items from this list.

Open the Microsoft SQL Server Management Studio (SSMS) version you want to affect. Open the Connect to Server dialog (File->Connect Object Explorer, Object Explorer-> Connect-> Database Engine, etc). Click on the Server Name field drop down list’s down arrow. Hover over the items you want to remove. Press the delete (DEL) key on your keyboard.

there we go.


Works with SQLServer 2014
Works with SQL Server 2016 Management Studio.
What the hell! I read it and was like WHAT! How would anyone intuitively guess this. I tried and it worked. UX is not a Microsoft strong point.
@rbassett Re-read the answer -> Don't select the item you want to delete, instead open the dropdown, hover over the item (without selecting) and then press the DEL key. I've never seen anything like this before, but it works!
@Radderz you are right, I had selected it rather than hovering over, well spotted. However I also have multiple logins for the same server, one of which I wanted to remove and so editing that xml file meant I could remove the login I didn't want whilst leaving the other logins for that server still there.
R
Raj More

For SQL 2005, delete the file:

C:\Documents and Settings\<USER>\Application Data\Microsoft\Microsoft SQL Server\90\Tools\Shell\mru.dat

For SQL 2008, the file location, format and name changed:

C:\Documents and Settings\<USER>\Application Data\Microsoft\Microsoft SQL Server\100\Tools\Shell\SqlStudio.bin

How to clear the list:

Shut down all instances of SSMS Delete/Rename the file Open SSMS

This request is registered on Microsoft Connect


I open the SqlStudio.bin, the file is big, it seems possible contain other information,what will lose other than connection history?
The file contains user settings - anything that you have customized will be lost. If you have some .Net or Powershell skills, look at this answer stackoverflow.com/questions/6230159/…
In widnows 7 it's under C:\Users\\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell
It's a pity, that I can't delete exactly group of server, not all my user settings.
PROCEED WITH CAUTION. This doesn't actually do what the OP asked, which was to remove individual items. This blows away all items, and other preferences too.
C
Community

Over on this duplicate question @arcticdev posted some code that will get rid of individual entries (as opposed to all entries being delete the bin file). I have wrapped it in a very ugly UI and put it here: http://ssmsmru.codeplex.com/


Worked well for me for SSMS 2008 R2 (10.50.1777.0), but to be sure I had overwritten the included DLLs with ones from the SSMS directory. As far as I can tell, all other settings remained intact. Thanks!
@Mark - Thank you very much. A side note: if you have two servers with the same name, even if they have different login authentication types, and you delete one, it will delete them both.
I know this was built for 2008, but in case anyone is interested, I tried this tool on SSMS 2014. I had to change the config file to look in the right directory, and it was able to find the servers in the bin file, but when I clicked on save and then opened SSMS, all of my servers were gone, instead of just the one I deleted. Luckily I backed up my bin file first. :)
The binaries are different for 2014 - I haven't done a 2012/2014 version as it is possible to delete server from SSMS. If there was interest I could try and fnd some time to create.
@Mark This worked perfectly for MSSQL 2008 R2 Management Studio. I'm glad I kept reading through the comments/answers and found this one.
D
Damian Powell

For SQL Server 2012 Management Studio, this file has moved. It is now located at:

C:\Users\<username>\AppData\Roaming\Microsoft\
    SQL Server Management Studio\11.0\SqlStudio.bin

And for SSMS 2014, it is now at c:\Users\<username>\AppData\Roaming\Microsoft\SQL Server Management Studio\12.0\SqlStudio.bin but I'm guessing that was kind of obvious.
quicker to reach using: %appdata%\Roaming\Microsoft\ SQL Server Management Studio\11.0\SqlStudio.bin
R
Richard Marskell - Drackir

In Windows Server 2008 standard with SQL Express 2008, the "SqlStudio.bin" file lives here:

%UserProfile%\Microsoft\Microsoft SQL Server\100\Tools\Shell\

This doesn't help. The file will be recreated with the same users in it.
@nima you may need to close SSMS before deletig the file. Also see my answer for a way to delete individual items.
D
David Sanders

Delete the file from above path: (Before delete please close SSMS)

File location path for the users of SQL Server 2005,

C:\Documents and Settings\%USERNAME%\Application Data\Microsoft\Microsoft SQL Server\90\Tools\Shell\mru.dat

File location path for the users of SQL Server 2008,

Note: Format Name has been changed.

C:\Documents and Settings\%USERNAME%\Application Data\Microsoft\Microsoft SQL Server\100\Tools\Shell\SqlStudio.bin

File location path for the users of Server 2008 standard/SQL Express 2008

C:\Documents and Settings\%USERNAME%\Microsoft\Microsoft SQL Server\100\Tools\Shell\SqlStudio.bin

File location path for the users of SQL Server 2012,

C:\Users\%USERNAME%\AppData\Roaming\Microsoft\SQL Server Management Studio\11.0\SqlStudio.bin

File location path for the users of SQL Server 2014,

C:\Users\%USERNAME%\AppData\Roaming\Microsoft\SQL Server Management Studio\12.0\SqlStudio.bin

Note: In SSMS 2012 (Version 10.50.1600.1 OR Above), ow you can remove the server name by selecting it from dropdown and press DELETE.


For SQL Server Management Studio 18.8 I found the server settings in C:\Users\USERNAME\AppData\Roaming\Microsoft\SQL Server Management Studio\18.0\UserSettings.xml
P
Pang

Here is an easy way.

Open the connection window, click on the Server name dropdown, and hover over the connection string you want to delete, then press delete.


T
Tommy Grovnes

In SSMS 2012 there is a documented way to delete the server name from the "Connect to Server" dialog. Now, we can remove the server name by selecting it in the dialog and pressing DELETE.


verified with SSMS 11.0.3128.0 this does not work. Probably got nixed because it clouds the native delete behavior. (The MSDN post makes a point of saying the previous item text will remain in the box after deleting, which is a poor UX decision. What if I just wanted to delete the text, and not the saved entry?)
In my case, I have 11.0.3000.0 version and It works fine. Just you need to click drop down, select server and then click delete. Yes, it's little confusing.
where do you 'click' delete? There is no delete button in my UI. Still, even just hitting the delete key simply deletes the text in the ComboBox, and the entry remains in the dropdown.
Sorry my mistake, instead of "click delete", I should have written "press delete key". There is no button for delete, you need to press Delete key from Keyboard.
C
Community

File SqlStudio.bin actually contains binary serialized data of type "Microsoft.SqlServer.Management.UserSettings.SqlStudio".

Using BinaryFormatter class you can write simple .NET application in order to edit file content.


See my answer for a simple UI that I have wrapped around this code.
g
ggponti

From the Command Prompt (Start \ All Programs \ Accessories \ Command Prompt):

DEL /S SqlStudio.bin

s
sergiommaria

This is the correct way of doing it http://blogs.msdn.com/b/managingsql/archive/2011/07/13/deleting-old-server-names-from-quot-connect-to-server-quot-dialog-in-ssms.aspx


Above is the easy supported way and works with 2012 and above.
Link is broken now.
a
abatishchev

For Windows Vista and SQL Server 2005,

Delete this file, or open it with the Notepad and clear the server names that you want Clear from the history

%UserProfile%\Microsoft\Microsoft SQL Server\90\Tools\Shell\mru.dat

P
Peter

C:\Users\\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell


P
Pang

Rather than deleting or renaming this file:

Close SQL Server Management Studio. Find the appropriate file (see the other posts). Open the .bin in a text/hex editior like NotePad++. Search for the name of one of the servers and identify the line number. Make a copy of the .bin/.dat file. Delete that line. Make sure you delete the entire line, it's possible if you have many the line could wrap. Open SQL Server Management Studio. Your dropdown will be blank.