Sqlcmd

In SQL Server 2005, Microsoft replaced the familiar command-line tool Osql with Sqlcmd. Both tools perform similar functions, with subtle differences. For example, each tool can connect to a SQL Server instance for direct queries or batch job initiation. And, for my project, they can both perform the invaluable service of listing all listening SQL Server machines on the network. One of Sqlcmd’s subtle differences is that you can use the command-line option /Lc rather than just /L to derive the server list:

sqlcmd /Lc

The c is important in the command because it produces clean output in the server list. If you don’t use the c, the resulting list will contain a header (i.e., Servers:), and each server name will have leading spaces. This situation isn’t ideal for the next phase of my project, in which you load the command output into a table to subsequently use as input to the SSIS package. This package, in turn, will automatically connect to each of these servers to retrieve specific information. You use Sqlcmd solely to get this list of servers. By itself, the command is useful to gain the first level of understanding of the SQL Server machines on your network. However, at this point it reveals nothing more than a server or instance name.

Discuss this Article 4

billykanthug
on Apr 23, 2008
i used sqlcmd /Lc or /L and returned null, but i do have sql installed..??
rlandrum
on May 6, 2008
I am not sure unless maybe you have a combination of security settings that are preventing browsing to the servers...Firewall ports blocked, SQL Browsing disabled, listening on ports other than default, hidden servers?
rlandrum
on Jan 14, 2010
"sqlcmd /Lc" works well for me.
aburro
on Jan 4, 2010
the syntax given above is incorrect. Use SQLCMD -Lc and press

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottOur Experts will show you:
• Common SQL Server
Problems
• Best Practices for T-SQL
• SQL Server Integration
Services
• Database Development

Come See Michael Otey & Tim Ford in Person!

Early Registration Now Open

From the Blogs
May 21, 2013
blog

A Common Misconception about MAXDOP

Out of the box, SQL Server is (and has been) able to take advantage of multiple processors/cores without any effort on behalf of administrators....More
May 9, 2013
blog

My ISO 8601-Compliant Signature 2

My family recently just "officially" announced that we're in the process of adopting a child from South Africa. We're quite excited, of course, but there's a ton of paperwork to do—along with the need for gobs of signatures....More
May 8, 2013
blog

Use SSIS for ETL from Hadoop

In this blog post, Mark Kromer walks you through using SSIS as a way to use ETL techniques using Microsoft's Hadoop on Windows (HDInsight) as a source using Hive connectors...More
SQL Server Pro Forums

Get answers to questions, share tips, and engage with the SQL Server community in our Forums.