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 >
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);
}
}
}
正如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上。