question

trang-0066 avatar image
0 Votes"
trang-0066 asked Criszhan-msft edited

SQLCMD -L return no servername

Hi all,

I'm facing an issue when wan to display all servername using sqlcmd -L command. However, it returns no servername. I already install SQLEXPRADV_64_ENU that already include localDB, sql server management studio and other features. could anyone help me on this issue, it's very tricky when I have to read server name from sql server configuration management to connect database from cli.118488-servername.png


sql-server-general
servername.png (5.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

OlafHelper-2800 avatar image
0 Votes"
OlafHelper-2800 answered

See sqlcmd [Utility => Parameter -L[c] => Note][1]

"Because of the nature of broadcasting on networks, sqlcmd may not receive a timely response from all servers. Therefore, the list of servers returned may vary for each invocation of this option."

That function haven't ever been reliable

[1]: https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-ver15#command-line-options


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Criszhan-msft avatar image
0 Votes"
Criszhan-msft answered Criszhan-msft edited

Hi,

As Olaf said, this command has been explained in the documentation, which may not be so practical.

You can check the SQL Server errorlog to determine the server name (search for "Server name"). According to the version of SQL Server you installed, By default, the errorlog is located at C:\Program Files\Microsoft SQL Server\MSSQLnn.instancesName\ MSSQL\LOG\ERRORLOG, nn corresponds to 15 for SQL Server 2019,14 for SQL Server 2017.

Or start SSMS locally on the server where SQL Server is installed, and then choose the <Browse for more…> option in the Server name field in the connection window box.

How to find all localdb instance names please refer to this post.
https://stackoverflow.com/questions/36157191/sql-server-how-to-find-all-localdb-instance-names

To connect to the SQL Server database, you can use the server name, or server name\instance name (for the named instance), or the IP address.
https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/logging-in-to-sql-server?view=sql-server-ver15

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.