wood burning stoves 2.0*
The moose likes JDBC 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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Win32Exception: Failed to open Watch "Win32Exception: Failed to open New topic
Author

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

Mukund Patil
Greenhorn

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?

Thanks,
Mukund
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Win32Exception: Failed to open 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_5
 
Similar Threads
Ant, JDBC, MS SQL Server
Test failed: The connection to the host localhost, named instance moeincom has failed
MS SQL Server / JDBC / Ant problems
Some virus????
Tomcat(jdk1.3.1) - Win2k service - GC output