Questions tagged [osql]

a command-line utility that allows users to execute Transact-SQL (TSQL) statements and scripts.

The osql utility is a command-line utiilty that allowers users to execute Transact-SQL statements and scripts, with the results either returned to the command prompt, or a text file if specified.

For more information, including switches, see the MSDN documentation or enter osql /? in the command prompt.

56 questions
14
votes
1 answer

Directory lookup for the file failed with the operating system error 3 (The system cannot find the path specified.)

I am trying to re-create a database (MyDB) from one SQL server (Source) to another one (Target). Source is located on my local machine and is SQL Server 2014. Target is located on a remote machine and it's SQL Server 2012. Here are the steps I've…
lukegf
  • 1,797
  • 3
  • 17
  • 35
4
votes
3 answers

Running queries using osql

When executing any one of the following commands: osql -E -S ComputerName\InstanceName osql -E -S ComputerName\InstanceName -i MyScript.sql -o MyOutput.rpt osql -E -q "SELECT * FROM Northwind.dbo.Shippers" osql -E -Q "SELECT * FROM…
Alex Gordon
  • 51,480
  • 273
  • 609
  • 976
4
votes
2 answers

Issues running scripts through osql.exe

I try and run update scripts for my software in this format: osql.exe -i "path\to\script" -U "user" -P "Password" -S "Location of sqlserver" -d "Database name" -n -b Most of the scripts are in the same format and all end in GO. A lot of them run…
user1427105
  • 457
  • 11
  • 23
3
votes
2 answers

powershell $LastExitCode -1073741502 when calling osql or sqlcmd

I've written a powershell script to call sqlcmd.exe to execute a sql script against a remote sql server. The powershell script checks $LASTEXITCODE. If $LASTEXITCODE is non zero, I throw "Script failed. Return code is $LASTEXITCODE." The script…
richard wadsworth
  • 131
  • 1
  • 2
  • 5
3
votes
2 answers

Does anyone has quick "cheat cheat" or "commandline reference" for OSQL?

a friend of mine complained that SQL managment studio express is prohibited by some security setting set by his system admin. i recommended to use OSQL my question is i need some basic orders like best way to attach, detach and deal with SQL…
Mohamed Kamal
  • 2,327
  • 3
  • 29
  • 46
3
votes
2 answers

Can osql.exe run as a standalone?

I have a program that runs osql.exe from microsoft sql server tools directory and runs a script. The problem is that on computers that don't have an installation of sql server, this tool is missing. So my question is whether or not is possible to…
Konstantinos
  • 12,305
  • 9
  • 46
  • 59
3
votes
2 answers

Which dll's are required to run osql.exe as a standalone?

According to the accepted answer to this question, the osql.exe utility can be run as a standalone program on a computer without SQLServer, simply by copying the binary file to the new computer. My question is, however, which other files need to be…
chama
  • 5,537
  • 13
  • 57
  • 72
3
votes
1 answer

Data source name not found and no default driver specified

I am trying to connect to list the servers on my network using osql.exe -L. Instead of a list of servers, however, I get the following error: [ODBC Driver Manager] Data source name not found and no default driver specified I'm not sure what's…
chama
  • 5,537
  • 13
  • 57
  • 72
2
votes
1 answer

Equivalent of MySQL's SOURCE command to load a script for TSQL?

In MySQL, you can issue commands like this: drop database foo; create database foo; use foo; source c:\src\bar.sql The source statement loads a external script and runs it. What's the equivalent in SQL Server?
dan_l
  • 1,682
  • 2
  • 22
  • 39
2
votes
2 answers

Msg 102, Level 15, state 1 Line 1 Incorrect syntax near 'n'

I have the following query which I am running using a batch file. In the batch file I use the following syntax: echo populating Application table with values... SET "installFile=%sqlDir%\Install\DataFiles\Insert_ApplicationNames.sql" OSQL /n /i…
EndlessSpace
  • 1,110
  • 2
  • 22
  • 41
2
votes
2 answers

SQL Server Login Using OSQL.exe

From Visual Studio 2010 I can connect to my SQL Server Express 2005 instance - by specifying windows authentication. However, when I use a command like it doesn't work: C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>osql -S SQLEXPRESS -U…
Brent Arias
  • 26,187
  • 32
  • 120
  • 209
2
votes
1 answer

Using FreeTDS and UnixODBC. Able to connect but cannot execute any SQL commands from isql or RODBC

This one is really starting to stump me. I'm running Ubuntu 12.04 and am trying to connect to a box running MS SQL server 2012. First I'll provide some information on my setup: My freetds.conf: [EXNAME] host = IP port = 1433 tds version…
JoeC
  • 53
  • 1
  • 6
2
votes
1 answer

How to remove blank records returned from osql?

I have a batch script which runs an sql query on multiple databases and appends the results to a .dat file. The script is adding 3 blank lines under the result from each database & also at the top of the file. Im using the below osql command to run…
2
votes
1 answer

SQL query works inside SSMS but not when using osql command in cmd file

Im having trouble getting a certain query to work outside SSMS. The query gathers all the user defined data types and creates IF EXISTS statements and CREATE TYPE commands for easy transferring of all the user-defined data types. The query to do so…
Hub3rt
  • 113
  • 1
  • 9
1
vote
1 answer

osql does not execute query

I have a system where I only have osql available (SQL2K Express). I execute queries and at one moment it stopped displaying any results. It seems that actually it does not execute the queries (because an erroneous script does not show an error). I…
florin
  • 406
  • 4
  • 18
1
2 3 4