Solved

Help needed regarding OSQL utility !!

Posted on 2008-06-25
8
264 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 82

Expert Comment

by:oBdA
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:milani_lucie
Comment Utility
C:\>Sample.cmd
---------------
--- Setup START
---------------
The syntax of the command is incorrect.
C:\>
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
Hi angelIII:

Here is the error i have caught...

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

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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 82

Expert Comment

by:oBdA
Comment Utility
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now