删除SQL Server Management Studio中记住的登录名和密码列表

最近,当我的笔记本电脑正在维修时,我用了我们公司的备用笔记本电脑(它有一个普通用户设置)。我在SQL Server Management Studio中检查了登录数据库时的“记住密码”选项。

我需要清除我曾经使用的登录名和密码信息,以防止下一个将使用笔记本电脑的人使用我的登录名和密码。我该怎么做呢?

155905 次浏览

删除:

C:\Documents and Settings\ %您的用户名%\应用程序数据\Microsoft\Microsoft SQL Server\90\Tools\Shell\mru.dat"

这里的另一个答案也提到,自2012年以来,你可以删除通过如何从连接到服务器对话框中删除缓存的服务器名称?删除缓存的登录。刚刚确认MRU列表中的删除在2016年和2017年工作正常。

SQL Server Management Studio 2017删除文件 C:\Users\%username%\AppData\Roaming\Microsoft\SQL Server Management Studio\14.0\SqlStudio.bin < / p >

SQL Server Management Studio 2016删除文件 C:\Users\%username%\AppData\Roaming\Microsoft\SQL Server Management Studio\13.0\SqlStudio.bin < / p >

SQL Server Management Studio 2014删除文件 C:\Users\%username%\AppData\Roaming\Microsoft\SQL Server Management Studio\12.0\SqlStudio.bin < / p >

SQL Server Management Studio 2012删除文件 C:\Users\%username%\AppData\Roaming\Microsoft\SQL Server Management Studio\11.0\SqlStudio.bin < / p >

SQL Server Management Studio 2008删除文件C:\Users\%username%\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell\SqlStudio.bin

SQL Server Management Studio 2005删除文件-与上面的答案相同,但Vista的路径。 C:\Users\%username%\AppData\Roaming\Microsoft\Microsoft SQL Server\90\Tools\Shell\mru.dat < / p >

这些是Vista / 7 / 8的配置文件路径。

编辑:

注意,AppData是一个隐藏文件夹。你需要在资源管理器中显示隐藏文件夹。

< p >编辑: 您可以简单地从服务器/用户名下拉菜单中按下delete(确认适用于SSMS v18.0)。来自https://blog.sqlauthority.com/2013/04/17/sql-server-remove-cached-login-from-ssms-connect-dialog-sql-in-sixty-seconds-049/的原始源代码,其中提到该功能自2012年以来可用!< / p >

在XP中,.mru.dat文件位于C:\Documents and Settings\Name\ Application Data\Microsoft\Microsoft SQL Server\90\Tools\ShellSEM中

然而,删除它并没有任何作用。

要在XP中删除列表,请从C:\Documents and Settings\Name\ Application Data\Microsoft\Microsoft SQL Server\100\Tools\Shell中剪切sqlstudio bin文件,并将其粘贴到桌面上。

尝试SQL

如果它已经工作,那么从桌面删除sqlstudio bin文件。

容易:)

对于那些寻找SSMS 2012解决方案的人…请看这个答案:

删除缓存的登录2012

从本质上讲,在2012年,你可以从服务器列表下拉列表中删除该服务器,这将清除该服务器的所有缓存登录。

也适用于v17 (build 14.x)。

SQL Server Management Studio 2008

  1. 你需要去C:\Documents and Settings\%username%\Application Data\Microsoft\Microsoft SQL Server\100\Tools\Shell

  2. 删除<强> SqlStudio.bin < / >强

在我的场景中,我只想从列表中删除一个特定的用户名/密码,该列表中还有许多其他我不想忘记的保存连接。事实证明,其他人在这里讨论的SqlStudio.bin文件是Microsoft.SqlServer.Management.UserSettings.SqlStudio类的. net二进制序列化,可以反序列化、修改和重新序列化以修改特定的设置。

为了完成特定登录的删除,我创建了一个新的c# .Net 4.6.1控制台应用程序,并添加了一个对位于以下dll中的命名空间的引用:C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\ManagementStudio\Microsoft.SqlServer.Management.UserSettings.dll(根据SSMS版本,您的路径可能略有不同)

从那里,我可以轻松地创建和修改所需的设置:

using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Microsoft.SqlServer.Management.UserSettings;


class Program
{
static void Main(string[] args)
{
var settingsFile = new FileInfo(@"C:\Users\%username%\AppData\Roaming\Microsoft\SQL Server Management Studio\13.0\SqlStudio.bin");


// Backup our original file just in case...
File.Copy(settingsFile.FullName, settingsFile.FullName + ".backup");


BinaryFormatter fmt = new BinaryFormatter();


SqlStudio settings = null;


using(var fs = settingsFile.Open(FileMode.Open))
{
settings = (SqlStudio)fmt.Deserialize(fs);
}


// The structure of server types / servers / connections requires us to loop
// through multiple nested collections to find the connection to be removed.
// We start here with the server types


var serverTypes = settings.SSMS.ConnectionOptions.ServerTypes;


foreach (var serverType in serverTypes)
{
foreach (var server in serverType.Value.Servers)
{
// Will store the connection for the provided server which should be removed
ServerConnectionSettings removeConn = null;


foreach (var conn in server.Connections)
{
if (conn.UserName == "adminUserThatShouldBeRemoved")
{
removeConn = conn;
break;
}
}


if (removeConn != null)
{
server.Connections.RemoveItem(removeConn);
}
}
}


using (var fs = settingsFile.Open(FileMode.Create))
{
fmt.Serialize(fs, settings);
}
}
}

这适用于SQL Server Management Studio v18.0

文件“sqlstudio .bin”;似乎已经不存在了。相反,我的设置都存储在这个文件中:

C:\Users\*********\AppData\Roaming\Microsoft\SQL Server Management Studio\18.0\UserSettings.xml

  • 在任何Texteditor如notepad++中打开它
  • Ctrl +f表示要删除的用户名
  • 然后删除整个<Element>.......</Element>

<强>编辑: 对于v18.0(预览7),一个更简单和有效的解决方案是:

  • 进入“连接到服务器”;对话窗口:

    enter image description here

  • 单击屏幕截图中绿色的向下箭头。

  • 使用键盘上的方向键向上/向下导航

  • 按键盘上的DEL键删除条目。

  • 关闭对话窗口,当你重新打开它时,该条目确实会被删除。

希望能有所帮助:-)

正如glueks指出的,在Microsoft SQL Server Management Studio中没有SqlStudio.bin。我还在C:\Users\userName\AppData\Roaming\Microsoft\SQL Server Management Studio\18.0中找到了这个UserSettings.xml。但是删除包含凭据的<Element>似乎不起作用,如果我关闭并重新打开它,它会返回到xml文件上。

事实证明,你需要首先关闭SQL Server Management Studio,然后在你最喜欢的编辑器中编辑UserSettings.xml文件,例如Visual Studio Code。我猜它被缓存在SSMS的某个地方除了这个xml文件?!它不在Control Panel\All Control Panel Items\Credential Manager\Windows Credentials上。

有一个非常简单的方法来做到这一点,使用最新版本的SQL Server Management Studio(我使用的是18.4)

  1. 打开“Connect to Server”对话框
  2. 点击“服务器名”下拉菜单,打开
  3. 按下键盘上的向下箭头以突出显示服务器名称
  4. 按下键盘上的删除键

登录了!不要乱动dll或bin文件。

删除整个节点“元素”;(在“Connections"tree)来自XML文件,由版本18或更高版本使用。

C:\Users\%username%\AppData\Roaming\Microsoft\SQL Server Management Studio\18.0\UserSettings.xml

enter image description here

选择Login下拉箭头。从列表中删除用户