![]() |
|
|
By: Edgewood Solutions | Read Comments (2) | Print Edgewood Solutions is a technology company focused on Microsoft SQL Server and founder of MSSQLTips.com. Related Tips: More |
|
Problem
A common problem noted among database managers and network administrators is the number of unauthorized SQL instances on a network. Without proper application of service packs and hotfixes these instances create holes through which hackers and others can exploit the database infrastructure. Another situation you may find yourself in is needing to connect to a server instance whose name you can't recall. In either case you can find what you need by using OSQL or SQLCMD.
Solution
OSQL is a command-line utility that can be used to query a database and perform other administrative tasks. It can be accessed on one server and allow you to issue commands to another directly through a command prompt, SQL Server Agent job steps, or batch files. To check the instances currently installed on the network, open a command prompt and enter OSQL -L or OSQL /L. The OSQL application listens for other SQL Servers on the both the Named Pipes and TCP/IP. Through a packet "sniffing" application like Ethereal you can see that the OSQL application sends a service announcement on port 1434 (UDP):
Once the list of servers is returned you will notice that there are two listings for each server-one for Named Pipes and one for the servers listening on the TCP/IP ports (when the network interface is disabled only the instances on Named Pipes will be returned):
SQLCMD is another command-line utility included with SQL Server 2005 that replaces OSQL. There are some subtle differences between OSQL and SQLCMD, particularly as it relates to using the /L switch. The first difference is that it produces a cleaner list, naming an instance only once in the list of servers. It also sends numerous service advertisements prior to returning the list, as noted in this screenshot:
To find a list of SQL instances currently installed in your environment, open a command prompt and type SQLCMD /Lor SQLCMD -L:
Next Steps
| Share: | Share | Tweet |
|
![]() |
![]() |
Free SQL Server Learning |
| Sunday, August 01, 2010 - 2:12:59 AM - prem | Read The Tip |
|
if i execute osql -L it is not displaying a instance which is in the list..... is that due to fire wall or port issue or shud i add anything in sql to get that listed?????? Help me out on this |
|
| Friday, November 19, 2010 - 9:54:00 AM - George Squillace | Read The Tip |
|
What happens when someone installs the "Windows Internal Database"? It seems that neither OSQL nor SQLCMD arrive with that installation, and I can't use OSQL -S nor SQLCMD -S (with -L) to interrogate remotely? So, I also don't know what the instance name is on the machine with the Windows Internal Database. |
|
|
privacy | disclaimer | copyright | advertise | about authors | contribute | feedback | giveaways | user groups Some names and products listed are the registered trademarks of their respective owners. Edgewood Solutions LLC | MSSharePointTips.com | MSSQLTips.com |