File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Win32Exception: Failed to open 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Win32Exception: Failed to open Watch "Win32Exception: Failed to open New topic

Win32Exception: Failed to open 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_5

Mukund Patil

Joined: Feb 12, 2009
Posts: 16
Hi am getting the

Win32Exception: Failed to open 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQLServer\Parameters', error 2.: 2

issue to get the path of MS SQL Server using code -

if (RegistryKey.keyExists("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\MSSQL10_50.MSSQLSERVER\\MSSQLServer\\Parameters"))

the same code works on XP 32 bit machine but not working on any 64 bit window 7 or win 2003 server machine.

could you some one help me please?

Martin Vajsar

Joined: Aug 22, 2010
Posts: 3733

By far the best solution would be to make do without reading the registry. Why do you need to get the path where MS SQL Server is installed?

Anyway: you've probably run into the remapping of directories and registry keys which some exceptionally bright mind introduced into 64-bit versions of Windows. When a 32-bit application running on 64-bit Windows tries to access certain files or registry keys, the operating system silently redirects the request into other directories/registry keys. The net result is that 32bit and 64bit application sees different files/registry values when using the same name. (See how useful is that? I don't.)

While a 32-bit application can probably circumvent these redirections somehow, I'd suggest to simply run your application using 64-bit version of the JVM. This way your application won't be subject to these redirections. If this solution is not acceptable to you, you'll need to google up something like WOW64 redirections. I'm really no expert on this and I'm battling this insanity myself from time to time.
I agree. Here's the link:
subject: Win32Exception: Failed to open 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_5
It's not a secret anymore!