Installing sqlcmd and bcp on a Clean Machine

A clean Windows machine has no SQL Server tools just because it can reach a database. Installing sqlcmd and bcp takes the right package, a PATH check, and a real connection test.

A new hand plane cutting a single thin curl of shaving from a pine board clamped in a vise

Know Which sqlcmd You Want

Microsoft provides an ODBC based sqlcmd with the SQL Server command line utilities. There is also a newer Go based sqlcmd distributed separately. They share a name but have different feature sets and command behavior. bcp comes with the Microsoft command line utilities package, alongside the ODBC sqlcmd.

I decide which sqlcmd a script expects before installing sqlcmd and bcp. A machine can have more than one sqlcmd.exe on PATH. The first match wins when you type the bare command. That can change after an installer or PATH edit.

Which utility does your deployment script expect? Read its flags and test them against the chosen executable. A familiar file name is not a compatibility guarantee.

Get the Current Windows Package for Installing sqlcmd and bcp

Use Microsoft’s official download instructions for the command line utilities and the required ODBC driver. Check the Windows version and processor architecture in the current system requirements. Keep the installer package identity with your build record. Do not use an old feature pack because an archived page looks familiar.

Install through your approved software process. A workstation and an application server can have different policies. A command line utility does not require a full Database Engine installation just to connect to a remote server.

I keep the installer in the standard software catalog so another DBA can rebuild the machine. A tool installed by memory is a tool that disappears during the next laptop replacement.

Find Every Copy on PATH

Open a fresh terminal after installation. Run where.exe for both executable names. It shows every matching path in PATH order. If two sqlcmd copies appear, identify which is ODBC and which is Go. Do not assume the most recently installed copy is the one that runs.

A stale terminal can keep an old PATH value. Close it and open a new one before declaring installation failed. If the program is installed but not on PATH, use its full path for a one time test and then repair PATH through your normal Windows configuration process.

I check PATH before I check the server. It is hard to troubleshoot login flags when the wrong executable is listening.

REM Command line
where.exe sqlcmd.exe
where.exe bcp.exe

Check Versions Separately After Installing sqlcmd and bcp

bcp reports its version with the version switch. The ODBC sqlcmd help output includes its utility version. The Go sqlcmd has its own version command. Record the utility versions separately from SQL Server ProductVersion. They have independent release cycles.

The standalone tools can have a different version number from the Database Engine CU. That is expected. Do not mark the utility wrong because its digits do not match the server’s. Check the tool’s own release information and support status.

Run the version commands in the same terminal and account that will run the job. A scheduled task can have a different PATH from your interactive session.

REM Command line
bcp -v
sqlcmd -?
From installer to a working tool: a diagram about the installing sqlcmd and bcp

Make a Safe First Connection

Test a read only query against an approved test instance. Use Windows authentication where that fits your environment. Do not place a SQL password in a command line, since process listings and logs can expose it. Confirm the server identity and engine version in the result.

The example uses a local default instance. Replace the server target with your approved instance, including the backslash for a named instance. A successful local test does not prove firewall or certificate settings for a remote host.

If encryption validation fails, fix the server certificate or connection settings deliberately. Do not paste a trust override into every script just to make the first test green.

REM Command line
sqlcmd -S . -E -Q "SELECT @@SERVERNAME AS ConnectedInstance, SERVERPROPERTY('ProductVersion') AS ProductVersion"

Test bcp Without Guessing the Format

bcp can export a query or table and import data. Before a real transfer, define encoding, delimiter, row terminator, and NULL handling with the receiving team. A file that contains rows is not automatically a valid CSV file. Test commas, quotes, line breaks, and Unicode.

Use a small approved test table or query first. Check the process exit code and inspect the destination file. Then load the sample through the receiving process. Do not infer compatibility from a text editor preview.

I keep bcp options with the job script. A one line command typed from memory can change the file contract. The receiver needs a repeatable format, not a lucky export.

Watch Driver Dependencies When Installing sqlcmd and bcp

The command line utilities use the Microsoft ODBC Driver for SQL Server. Install the required driver version and test the connection after deployment. A server patch does not update the local command line utilities or driver on every client machine.

Encryption and certificate defaults can change with newer drivers. Test scheduled jobs through the real service account and target name. A login that works for your administrator account can fail for the job account.

Keep the driver and tool versions in the workstation or server inventory. That makes a future connection failure easier to diagnose.

Prove the Automation Path

Run the command from the same Windows account and working directory as the intended scheduled task. Verify PATH, permissions, file locations, and error handling. Configure the job to stop on a nonzero process exit. Save output in a controlled log.

For sqlcmd scripts, check which utility implementation executes them. Test variable substitution, error flags, and authentication options before replacing an old executable. For bcp, compare a small file with the expected schema and data.

A clean machine is ready when both tools are found, their versions are known, and a real approved connection succeeds. The installer screen is only the first step.

Related reading on this blog: Simple Example of BCP Command Line Utility and Connecting to Server Using Windows Authentication by SQLCMD.

Prove the automation path: a checklist on the installing sqlcmd and bcp

A tool is not installed because its folder exists, it is installed when the right executable passes the job you need.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.

Command Line, DBA, SQL Server, SQL Utility, sqlcmd
Previous Post
Handing Over a Database to Another Team
Next Post
Slipstreaming Updates Into a New Install

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.