0

I am trying to write a program in Java which has to check if SQL Server (2008) is installed on a particular machine. Is checking the registry entry the only solution? I prefer a file-based solution.

Currently, I am checking for the presence of OSQL.exe (which I use to execute queries and SQL scripts) in the <Installation Path>\100\Tools\Binn folder. What does the 100 specify? Can it be hardcoded in the program, or will I have to search for the OSQL.exe file starting from the installation path?

3
  • 1
    100 is the version of SQL server, and specifically means you're dealing with a 2008 or 2008 R2 installation (Internally, 2008 is version 10.0, but they remove the "." in the path). 2005 installed primarily under a 90 directory, 2000 under 80, etc. Commented Aug 12, 2011 at 5:59
  • If you're already having to consult the registry (you are doing that, to find where it's been installed, aren't you?), then why is a subsequent file search going to "improve" the result. Commented Aug 12, 2011 at 6:01
  • @Damien: Thanks for the heads up. And about the registry check - No, I am not doing that! Commented Aug 12, 2011 at 6:20

2 Answers 2

0

Your question is a bit unclear, in particular it's not obvious if you need to enumerate local and/or remote instances? For local instances searching the registry is more reliable than scanning the file system, for remote instances sqlcmd.exe can list instances on the network. This page gives a good overview of the options (for 2005, but they are still valid for 2008).

If it's possible for you to call .NET from Java, you can use the Smo Server object to get a lot of information about the instances, including installation paths. There are numerous questions on this site about enumerating instances and gathering information about them.

Finally, please note that osql.exe is deprecated so you should be using sqlcmd.exe instead.

Sign up to request clarification or add additional context in comments.

2 Comments

I do not wish to enumerate the instances at all. All I need to check is if SQL Server is installed or not, that is all. And thanks for the link to sqlcmd, might want to look into that!
I don't see the difference: if there is at least one instance, then SQL Server is installed. The path to sqlcmd.exe is in the registry, but that doesn't mean that SQL Server is installed, just that the client tools are.
0

To me this method is messy and full of several unseen pitfalls. I would prefer the user to assert if the db is present and if yes, ask for the connection URL, username and pass using which you can try to create a simple jdbc connection to check if its running.

1 Comment

Well before asking the user for the server and DB details, I'd first like to check if SQL Server is installed. I'd like the user to provide the same path he/she used during SQL Server installation (for example, C:\Program Files\Microsoft SQL Server) and from then on, figure out, through code, where the OSQL.exe file is.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.