Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help needed regarding OSQL utility !!

Posted on 2008-06-25
8
Medium Priority
?
274 Views
Last Modified: 2010-05-18
Hi,

I have

D:\Tables
D:\SPs

directories. In D:\Tables, I have create tables scripts. Similarly in D:\SPs, I have create stored procedures scripts.

I have written a .CMD file to install these scripts in the database - creating tables / creating stored procedures etc...

D:\Sample.CMD
============

echo ---------------
echo --- Setup START
echo ---------------

FOR %%f IN
(
  ..\Tables\*.sql
  ..\SPs\*.sql

) DO (echo Executing %%f) & (osql -E -n -S localhost -d Sample -w 8192 -i %%f) || (echo Error %%f & exit)

echo ---------------
echo --- Setup END
echo ---------------

In this script:

Server - localhost
Database - Sample

This is NOT working properly when i double click on this file. Can you please FIX the above program and make it working ? BTW: when i double click on the file, it is showing the results and disappearing quickly. Can you make it stand by until i press any key ?

Thanks
0
Comment
Question by:milani_lucie
  • 4
  • 3
8 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 21878935
When testing batch scripts, always open a command prompt and start them from there, not through Explorer; that way, you'll be able to see the error.
Anyway, try this:
echo ---------------
echo --- Setup START
echo ---------------
 
FOR %%f IN ("..\Tables\*.sql" "..\SPs\*.sql" do (
  echo Executing %%f
  osql -E -n -S localhost -d Sample -w 8192 -i "%%f"
  if errorlevel 1 (
    echo Error %%f
    exit /b
  )
)
 
echo ---------------
echo --- Setup END
echo ---------------

Open in new window

0
 

Author Comment

by:milani_lucie
ID: 21879235
echo ---------------
echo --- Setup START
echo ---------------
 
FOR %%f IN
(
      "..\Tables\*.sql"
      "..\SPs\*.sql"
) DO (echo Executing %%f osql -E -n -S localhost -d Sample -w 8192 -i "%%f" if errorlevel 1 (echo Error %%f exit /b))
 
echo ---------------
echo --- Setup END
echo ---------------

This is NOT working. Can you please verify my code ? Please test on your side.

Thanks
0
 

Author Comment

by:milani_lucie
ID: 21879251
I have gone to command prompt and how to open the file ? Just type the name of the file ? Like this ?

C:\>Sample.CMD
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:milani_lucie
ID: 21879339
C:\>Sample.cmd
---------------
--- Setup START
---------------
The syntax of the command is incorrect.
C:\>
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21879371
please try this:
echo ---------------
echo --- Setup START
echo ---------------
 
FOR %%f IN (..\Tables\*.sql ) DO (echo Executing %%f osql -E -n -S localhost -d Sample -w 8192 -i "%%f" if errorlevel 1 (echo Error %%f exit /b))
 
FOR %%f IN (..\SPs\*.sql) DO (echo Executing %%f osql -E -n -S localhost -d Sample -w 8192 -i "%%f" if errorlevel 1 (echo Error %%f exit /b))
      
 
echo ---------------
echo --- Setup END
echo ---------------

Open in new window

0
 

Author Comment

by:milani_lucie
ID: 21879419
Hi angelIII:

Here is the error i have caught...

C:\>Sample.cmd
---------------
--- Setup START
---------------
) was unexpected at this time.
C:\>
0
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 21879446
Missing closing bracket in the first line, this works:
@echo off
echo ---------------
echo --- Setup START
echo ---------------
 
FOR %%f IN ("..\Tables\*.sql" "..\SPs\*.sql") do (
  echo Executing %%f
  ECHO osql -E -n -S localhost -d Sample -w 8192 -i "%%f"
  if errorlevel 1 (
    echo Error %%f
    exit /b
  )
)
 
echo ---------------
echo --- Setup END
echo ---------------

Open in new window

0
 
LVL 85

Expert Comment

by:oBdA
ID: 21879464
Sorry, forgot to remove the ECHO I put in for testing, currently the osql command will only be shown, not executed. Just remove the capitalized ECHO in front of the osql command.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question