I am trying to use the sqlcmd -L c command to find out the instance name of the SQL server running on the local machine. It succeeds, but I have to wait for a full minute, for the tool to realize that there are no other servers on the network.

Is there a way to set the sqlcmd -L timeout to a shorter time interval?


The point of -L is to find all the servers on the entire network, so you cannot bypass it scanning the entire network, and that switch will not work with other switches. The timeout is really related specifically to your network, and its configuration.

Are you just trying to find the instance names? What specifically are you trying to accomplish?

| improve this answer | |
  • Yes, I am trying to get the instance name. I am also exploring other options, like reading "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names", but my Windows scripting knowledge is failing me a bit... – Shade Jun 21 '11 at 14:48
  • @Shade How and why are you trying to get the instance name? If you just need to see it and find out what it is, there are easier ways, but if you need to address it for programmatic reasons, that is a bit harder and more specific. – KCotreau Jun 21 '11 at 14:51
  • P.S. You are not going to find the answer in the registry. It is just how long it takes to scan your network. BUT, there may be other ways, but you have to say what you want to accomplish, not what you want to do. – KCotreau Jun 21 '11 at 14:51
  • I just want to have the string name of the instance. I am going to use it in combination with the %hostname% variable to connect to my local server, as the script will not know the exact hostname\instance combination and TCP connections are disabled from the server configuration. – Shade Jun 21 '11 at 14:55
  • @Shade I don't know if this will help, but I created a file "script.sql" with this in it: select @@servername + '\' + @@servicename and then this command with sqlcmd: SQLCMD -i c:\temp\sqlquery1.sql /o c:\temp\instance.txt . You may then be able to extract the data and use in in your program from the output txt file. That script.sql will have to run on the SQL server. If not, you may have to live with the timeout period. – KCotreau Jun 21 '11 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.