3

We have some legacy .bat scripts full of osql commands to existing SQL Server instances / dbs on our network.

We've tried running the .bat scripts from our app server (Win Server 2008) but get the error: "osql.exe' is not recognized as an internal or external command"

We are hoping we don't need to install a full-blown SQL Server to get access to osql.

I've heard you can get it from the Client Tool installation, and no license required as long as connecting to licensed sql servers. (which we would be).

Can anyone confirm? Are "Client Tools" part of the installation discs?
Is this a viable solution?

Thanks for your help folks!

migrated from stackoverflow.com Apr 13 '14 at 14:35

This question came from our site for professional and enthusiast programmers.

  • OSQL.EXE is installed when you install SQL Server Management Studio (version 17.5) – ThePeter Mar 8 '18 at 19:23
7

The main recommendations appear to be:

  • If you have the install discs / files, then you should be able to install just the Client Tools.

  • Download SQL Server 2012 (SP1) Express (I would try the "SQL Server Management Studio Express (Tools only)" version first)

  • Check out: http://www.mssqltips.com/sqlservertip/1807/sql-server-2008-client-tools-installation/

  • If you already have a machine with OSQL installed, you might be able to copy just the following two files to the new server (place them in the same directory) and have it work:

    • C:\Program Files\Microsoft SQL Server\110\Tools\Binn\OSQL.EXE
    • C:\Program Files\Microsoft SQL Server\110\Tools\Binn\Resources\1033\osql.rll

As far as licensing goes, I found the following file:

C:\Program Files\Microsoft SQL Server\110\Tools\Binn\Resources\1033\license_SQLCMD.txt

That has the following snippet:

MICROSOFT SOFTWARE LICENSE TERMS MICROSOFT SQL SERVER 2012 COMMAND LINE UTILITIES
...
1. INSTALLATION AND USE RIGHTS. You may install and use any number of copies of the software on your devices to design, develop and test your programs.

Note:
OSQL has been superseded by SQLCMD. When you run OSQL it will display the following message:

Note: osql does not support all features of SQL Server 2012. Use sqlcmd instead. See SQL Server Books Online for details.

However, if your existing code expects OSQL then you would need to test SQLCMD with your code first to make sure that any behavior changes between OSQL and SQLCMD do not break your code.

  • Thanks for the feedback - will give install discs a shot. That might sound obvious, but that actually will take me a request to a different team. I'm sure you can appreciate why I was inquiring on right approach. No matter where I go, it will likely involve a different servicing team within our org. – knuckle05 Apr 13 '14 at 4:57
  • 1
    Since 2012 SP1 Express (download here), SQL Server Management Studio (SQLManagementStudio_x64_ENU.exe) is now a complete version rather than a feature-limited version of what you'd see in other editions. I'm not sure it includes osql (though I suspect it does), but I'd always recommend grabbing the SP1 installer over the original 2012 version. – Nathan Jolly Apr 13 '14 at 16:16
  • @knuckle05: You might not need the install discs. I just updated my answer with the idea of copying just the 2 relevant files. I tried it on my system and it worked so it is worth testing on your end as it does simplify things a bit. – Solomon Rutzky Apr 13 '14 at 19:37
  • @NathanJolly: Thanks! I have updated my answer with that link. – Solomon Rutzky Apr 13 '14 at 19:43
  • The text snippet about licensing is about "design, develop and test" of programs so it is not relevant for this post. – miracle173 Aug 12 '14 at 10:14
4

The tool you should be using is sqlcmd. It is installed with the client tools and replaces the deprecated osql.

0

This worked for me based on the tips provided:

  1. I copied osql.exe and dropped it into the C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn folder
  2. C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn was already assigned to the environment variable PATH

I was then able to run my batch file which required osql.exe. Note the version of osql.exe that I copied is very old (November 1998)

So thank you for providing useful information.

Your Answer

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