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
0
votes
1 answer

tidying up .BAT file

I have the script below which is performing correctly, but basically I want the .bat to ask the user if they want a list of casinos before entering the casino name and username, then, if they select l (lower-case letter EL) for list, it produces the…
Chris Wood
  • 498
  • 9
  • 27
0
votes
1 answer

Windows 7 OSQL Batch

I have just got a new work PC from running Windows 7. I have installed SQL Server 2008 and I have a batch file that runs an OSQL command as follow: osql -S MyServer -E -d MSDB -n -o results.txt -i MyScript.sql For some reason it is giving me…
odez213
  • 663
  • 3
  • 10
  • 23
0
votes
2 answers

SQLServer 2005 behavioral differences when using osql and sqlcommand

Is anyone aware of any subtle differences between the behavior of SQL Server 2005 when executing a command via OSQL vs. a programmatic query using SQlConnection? I have a client with a database on a remote machine that I can use OSQL to interact…
0
votes
1 answer

Run sql script on remote SQL Server database from my Linux machine

I have a .sql file in my linux machine. I would like to connect to MS SQL database in the remote windows machine and run the .sql file in that database. osql -S servername -U xx -P yy runs okay and returns a SQL window like: SQL> I can run…
0
votes
1 answer

OSQL TO SQLCMD Conversion

I am trying to convert OSQL comamnd to SQLCMD as below. The OSQL command is working fine,but converted SQLCMD is throwing below error, Please help. Original OSQL: osql.exe -S TestDB -E -d TestDB -Q EXIT("Declare @ExecutionResult int EXEC dbo.p_SP…
Pradeep H
  • 541
  • 2
  • 5
  • 25
0
votes
2 answers

Why I cannot change sa password using osql?

I got a laptop on which SQL Server Express is already installed. The server name is SRH\SQLEXPRESS and the version is 10.0.2531.0. The operating system is Windows 7. I can connect to it through Windows Authentication. But I would like to connect to…
srh
  • 1,427
  • 3
  • 22
  • 45
0
votes
1 answer

How can I use a cmd variable in an osql command?

I'm trying to run an osql command from a cmd shell. I need to use a cmd level variable within my osql command. For example, I have a variable %mydate%, and I want to pass it in as the value for the @start_date parameter in the following osql…
chama
  • 5,537
  • 13
  • 57
  • 72
0
votes
1 answer

Run OSQL on systems which do not have Sql Server installed

I have a batch file which runs an oSQL command (below). oSQL -U devUID -P testPwd -S testServer -d testDb -Q "EXEC [dbo].[sprocTEST]" When I run this batch file on systems which do not have sqlserver installed, it throws an error. "odbc driver…
jack
  • 1,308
  • 6
  • 23
  • 40
0
votes
0 answers

What am I doing wrong in this batch file?

When I run the below batch file code, it thinks that the server address is 'dbuser' and the Database is 'False' What am I doing wrong? Here is the code: @echo off set toolspath=C:\Program Files (x86)\Folder\Application Set…
0
votes
1 answer

ADODB COM Object returns -1 for bit values of 1

I am busy experimenting with ADODB as a means to write prepared scripts on customers' databases as it is infinitely better than batch scripting with sqlcmd. Early on I noticed that sometimes ADODB results would differ from the results given by osql…
KaoSDlanor
  • 65
  • 6
0
votes
1 answer

How to get results from OSQL.exe without dash characters from the command line?

Is there a way to send a osql query from the command line that returns results that do not include the big long line of dash characters that represent the column width? Here is the sample code I am working with: echo. "%PROGRAMFILES%\Microsoft SQL…
djangofan
  • 25,461
  • 54
  • 171
  • 262
0
votes
1 answer

OSQL Utility - porting a procedure to SQL Server 2014

I have a stored procedure which runs as a scheduled job on SQL Server 2008, and I am trying to migrate this to SQL Server 2014. The procedure generates html and populates the html with values from a local db. The scheduled job runs this proc and…
MarcKirby
  • 15
  • 5
0
votes
0 answers

Restore SQL Server database by using osql -q

I'm trying to restore a multiple disk/media back up using the below command when I use 1 or 2 disks its fine. In this case I am using 23. It fails with an error query is too long. Could not find any good solution .please help . osql -Q \"restore…
Arunachalam
  • 4,117
  • 19
  • 45
  • 75
0
votes
2 answers

T-SQL - List all databases on all servers within the network

I am trying to audit the network, to find and clean out old databases that may have been tested and forgotten. Right now, I know I can use SQLCMD -L to see the servers and instances. I can use exec sp_helpdb to get the Server name, name of the db,…
Billie Hawkins
  • 52
  • 1
  • 11
0
votes
1 answer

Retry OSQL command if deadlock occurs in FOR loop

So I am working on my first batch script that utilizes a OSQL query. Here is my current code: setlocal enableDelayedExpansion FOR /F %%G in (names.txt) DO ( :RESTARTER osql -b -D PCRServer -r -h-1 -s "," -i %%G.sql -o…