简体   繁体   中英

SQL Server 2008 R2 - .NET Framework unhandled exception

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)

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

Alan

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.

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM