Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way to detect if SQLCMD.exe is installed?

Tags:

c#

.net

sqlcmd

I am creating a class library that takes .SQL files as input (FileInfo) and a connection string. It then attempts to execute the sql file against the connection.

I have decided to support Microsoft's SMO and SQLCMD.exe

In testing, I have noticed on many machines in my environment, that SQLCMD does not come installed by default. My program errors when just attempting to run the process SQLCMD.exe.

What is the proper way to look for it without searching the entire hard drive? Is there a common registry location that specifies if it is installed? Usually when it is installed, I think a PATH location is set.

Many thanks.

like image 795
Issa Fram Avatar asked Dec 28 '11 06:12

Issa Fram


People also ask

How can I tell if SQLCMD is installed or not?

You could try to execute sqlcmd.exe -? in a process in your C# app - if it works, then SQLCMD is present - if not, it'll tell you something like "file not found" or "command invalid" or something ....

Where is SQLCMD installed?

The SQLCMD.exe binary is installed in the above mentioned directories such as C:\Program Files\Microsoft SQL Server\100\Tools\Binn\ for MSSQL 2008R2 installation. Under Binn there should be the Resources\1033 directory, containing SQLCMD.

How can I tell if SQLCMD is installed on Linux?

To check the SQLCMD version execute sqlcmd -? command and confirm that 15.0. 2000.5 version or higher is in use. You need version 13.1 or higher to support Always Encrypted ( -g ) and Azure Active Directory authentication ( -G ).


2 Answers

I have a 64 machine with 64 bit SQL SERVER (2k8 R2) and my SQLCMD.EXE is in c:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE.

It's also in the path.

You could just look for the path directly from the SQL Server Registry location:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\100\Tools\ClientSetup\path

Or a variant on this for a different version.

The big issue here is that SQLCMD is part of the client tools, not the SQL Server so I reckon you cannot ask SQL Server to tell you. Unless of course you're running on the server itself.

like image 82
Preet Sangha Avatar answered Sep 27 '22 15:09

Preet Sangha


Start cmd.exe and use

where sqlcmd.exe
like image 30
Dircar V. Avatar answered Sep 27 '22 17:09

Dircar V.