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.
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 ....
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.
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 ).
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.
Start cmd.exe and use
where sqlcmd.exe
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With