SQL Management Studio的凭证在哪里保存?

当我们通过选中“记住密码”login到SQL Management Studio(使用服务器名称,login和密码)时。 我需要知道,它保存在个人电脑中。

我需要格式化我的电脑。 而当我们安装SQLpipe理工作室,那么我将失去我保存的所有凭据。 这就是为什么我需要获取文件进行备份的地方。

知道什么版本的SQL Server以及您正在运行SSMS的操作系统会很有帮助。 这就是说,对于SQL Server 2008,它存储在SqlStudio.bin文件中:

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

这是我的理解,有很多其他设置存储在这里,只是简单地移动该文件的地方,可能会或可能不会为你工作。

假设您正在运行SQL 2008或更高版本,在Registered Servers窗口中,右键单击“DAtabase Engine”下的文件夹并selectTasks,然后selectExport。 指定一个文件并取消选中“不要在导出文件中包含用户名和密码”checkbox。 点击OK。 保护这个文件。 当你重build你的机器导入文件,你将拥有保存在列表中的所有东西。

这当然不是以纯文本保存的。 如果你不知道密码,你应该重置在服务器上。 由于这是一个系统pipe理员的网站,你一定要阅读常见问题 ,我假设你是服务器的pipe理员,可以做到这一点没有问题。

首先,您需要在SSMS中注册服务器。 在对象资源pipe理器中右键单击服务器并select注册或右键单击本地服务器组 ,select新build服务器注册并select服务器名称。 服务器密码将被填写,如果他们以前被记住。 然后按照@mrdenny的答案导出服务器。

现在来了棘手的部分。 您需要在目标计算机上的用户configuration文件下重新encryption密码。 我准备了一个PowerShell脚本,可以做到这一点。

 param( [Parameter(Mandatory=$true)] [string] $FileName, [Parameter(Mandatory=$true)][ValidateSet('Decrypt', 'Encrypt')] [string] $Operation ) $ErrorActionPreference = 'Stop' function Protect-String([string] $clearText) { return [System.Convert]::ToBase64String([System.Security.Cryptography.ProtectedData]::Protect([System.Text.Encoding]::Unicode.GetBytes($clearText), $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)) } function Unprotect-String([string] $base64String) { return [System.Text.Encoding]::Unicode.GetString([System.Security.Cryptography.ProtectedData]::Unprotect([System.Convert]::FromBase64String($base64String), $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)) } $document = [xml] (Get-Content $FileName) $nsm = New-Object 'System.Xml.XmlNamespaceManager' ($document.NameTable) $nsm.AddNamespace('rs', 'http://schemas.microsoft.com/sqlserver/RegisteredServers/2007/08') $attr = $document.DocumentElement.GetAttribute('plainText') if ($attr -eq '' -and $Operation -ieq 'Encrypt') { throw "The file does not contain plaintext passwords." } if ($attr -ne '' -and $Operation -ieq 'Decrypt') { throw "The file does not contain encrypted passwords." } $servers = $document.SelectNodes("//rs:RegisteredServer", $nsm) foreach ($server in $servers) { $connString = $server.ConnectionStringWithEncryptedPassword.InnerText if ($connString -inotmatch 'password="([^"]+)"') {continue} $password = $Matches[1] if ($Operation -ieq 'Decrypt') { $password = Unprotect-String $password } if ($Operation -ieq 'Encrypt') { $password = Protect-String $password } $connString = $connString -ireplace 'password="([^"]+)"', "password=`"$password`"" $server.ConnectionStringWithEncryptedPassword.InnerText = $connString } if ($Operation -ieq 'Decrypt') { $document.DocumentElement.SetAttribute('plainText', 'true') } else { $document.DocumentElement.RemoveAttribute('plainText') } $document.Save($FileName) 

在源机器上运行.\Move-SqlRegisteredServers.ps1 -FileName 'Your.regsrvr' -Operation Decrypt 。 这将用纯文本replaceencryption的密码。

在目标机上运行.\Move-SqlRegisteredServers.ps1 -FileName 'Your.regsrvr' -Operation Encrypt 。 这将使用新密钥再次encryption密码。

现在您可以将Your.regsrvr文件导入到SSMS中,并将您的服务器与保存的凭据一起使用。