9

I have installed SQL Server 2008 R2 on a new PC. Everything was working fine until I started exporting registered servers from the SQL Server 2008 R2 management studio which exist on my old PC. When I imported one of the registered servers to my new installation I got and error "Key not valid for use in specified state".

Now everytime I try to open registered servers on the new installation I get a .NET framework Unhandled Exception with the same message. The registered server area is completely empty. There is no way of adding any registered servers now. I have tried reinstalling SQL but the error remains. It is obviously related to the import process. Maybe something got corrupted. Does anyone know how to fix it?

Edit:Details from exception dialog

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Security.Cryptography.CryptographicException: Key not valid for use in specified state.

   at System.Security.Cryptography.ProtectedData.Unprotect(Byte[] encryptedData, Byte[] optionalEntropy, DataProtectionScope scope)
   at Microsoft.SqlServer.Management.RegisteredServers.RegisteredServer.ProtectData(String input, Boolean encrypt)
   at Microsoft.SqlServer.Management.RegisteredServers.RegisteredServer.get_SecureConnectionString()
   at Microsoft.SqlServer.Management.RegisteredServers.RegisteredServer.get_ConnectionString()
   at Microsoft.SqlServer.Management.RegisteredServers.RegisteredServer.get_ServerName()
   at Microsoft.SqlServer.Management.RegisteredServers.RegisteredServerTree.AddRegisteredServerNode(RegisteredServer regSrv, TreeNodeCollection nodes)
   at Microsoft.SqlServer.Management.RegisteredServers.RegisteredServerTree.AddServerGroupToNodeCollection(ServerGroup group, TreeNodeCollection nodes, Boolean createRecursively)
   at Microsoft.SqlServer.Management.RegisteredServers.RegisteredServerTree.AddServerGroupToNodeCollection(ServerGroup group, TreeNodeCollection nodes, Boolean createRecursively)
   at Microsoft.SqlServer.Management.RegisteredServers.RegisteredServerTree.Initialize(ServerGroup localServerGroup, ServerType serverType, IServerType connDlgServerType, AddCentralManagementServerDelegate onAddCentralManagementServer, AddNewCentralManagementServerDelegate onAddNewCentralManagementServer, DeleteCentralManagementServerDelegate onDeleteCentralManagementServer, GetServiceProviderDelegate onGetService)
   at Microsoft.SqlServer.Management.RegisteredServers.RegisteredServerControl.RegisteredServerControl_Load(Object sender, EventArgs e)
   at System.Windows.Forms.UserControl.OnLoad(EventArgs e)
   at System.Windows.Forms.UserControl.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.UserControl.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
1

5 Answers 5

15

Sounds like it is something in your windows profile (e.g. Users/[Username]/AppData/Roaming on Windows 7). Have you tried clearing the SQL Server entries from that?

Alan

4
  • 1
    Thanks Alan. Spot on. The offending file was RegSrvr.xml. I renamed it and restarted SQL Server. Error has gone. I will continue to add my registered servers manually!!
    – user718982
    Apr 22, 2011 at 9:36
  • Worked for me too but mine was under \Users\[Username]\AppData\Microsoft\Microsoft SQL Server. Also, because of the way the domain I'm on is configured it wasn't on my local machine but off on a network drive.
    – Molomby
    Feb 2, 2012 at 4:47
  • Thanks Alan, This worked for me too after clearing the RegSrvr.xml
    – zakirhas7
    Dec 11, 2012 at 21:36
  • deleted the file RegSrvr.xml but now after login i get a null error and no databases shown under Databases
    – SeanClt
    May 5, 2016 at 14:22
5

The RegSrvr.xml file was the problem for me too. But rather than delete the whole file, I just edited it to delete out the encrypted password strings. After that, Management Studio opened fine with all the imported servers present.

2
  • Brilliant! This is the solution.
    – mghaoui
    Jan 2, 2013 at 9:32
  • Similarly, I did another Export of the registrations from Sql Server Management Studio, but the second time I specified "Do not include user names and passwords in the export file". Then that imported fine into my new version instead of giving an error. So it seems that something goes wrong with including passwords in the SSMS export file.
    – Eric Barr
    Sep 21, 2015 at 21:28
2

I had avery similar situation. Exact same observations - but it had nothing to do with importing. I had done a complete reinstall of Windows 7, and SQL (Developer edition). I had recovered my profile from before the rebuild so it was out of sync with the install. I deleted C:\Users\John\AppData\Roaming\Microsoft\Microsoft SQL Server and the problem went away.

0

One more thing to check - you can't import exported definitions into earlier versions of SQL Management Studio. You'll get the same Key not valid for use error, for example, exporting from MSSMS2012 and trying to import in MSSMS2008R2.

0

One more thing to check - for me it was because there was no enough disk space in the drive of SQL Server. Clearing space resolved everything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.