Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help needed regarding OSQL utility !!

Posted on 2008-06-25
8
Medium Priority
?
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

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

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.

Question has a verified solution.

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

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

664 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