• subscribe
April 19, 2007 12:00 AM

Sqlcmd

SQL Server Pro
InstantDoc ID #95387

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.



ARTICLE TOOLS

Comments
  • RODNEY
    2 years ago
    Jan 14, 2010

    "sqlcmd /Lc" works well for me.

  • Craig
    2 years ago
    Jan 04, 2010

    the syntax given above is incorrect. Use SQLCMD -Lc and press

  • RODNEY
    4 years ago
    May 06, 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?

  • CHANG
    4 years ago
    Apr 23, 2008

    i used sqlcmd /Lc or /L and returned null, but i do have sql installed..??

You must log on before posting a comment.

Are you a new visitor? Register Here