Results 1 to 6 of 6
  1. #1
    Join Date
    May 2002
    Posts
    73

    Unanswered: Invoking or sending SQL queries using dOS

    Hello Folks,

    I want to create a simple batch DOS script to query mi SQL Server 2000 database. How I could do this?

    I just want to run a select for a table but I don´t want people to interct with sql query analyzer or enterprise manager to avoid any issues.

    Regards,

  2. #2
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    809
    Look up OSQL or ISQL in Books Online.

    Basically:
    OSQL -S <name of your server/instance> -U <UID> -P <PWD> -d <Database to use> -Q"<your select statment>" -n -b

    I do this all the time so post back if you have more questions.
    Paul Young
    (Knowledge is power! Get some!)

  3. #3
    Join Date
    May 2002
    Posts
    73

    OSQl

    Originally posted by Paul Young
    Look up OSQL or ISQL in Books Online.

    Basically:
    OSQL -S <name of your server/instance> -U <UID> -P <PWD> -d <Database to use> -Q"<your select statment>" -n -b

    I do this all the time so post back if you have more questions.
    UID stands for? PWD I assume is the pasword, isn´t.

    How I can redirect the results to a txt file,

    OSQL -S OSQL -S <name of your server/instance> -U <UID> -P <PWD> -d <Database to use> -Q"<your select statment>" -n -b >> query.txt

    Am I right?

    Thanks for your prompt reply and help

  4. #4
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    809
    UID = User ID

    You could pipe the output to a text file but the -o parm would be more usefull.
    Paul Young
    (Knowledge is power! Get some!)

  5. #5
    Join Date
    May 2002
    Posts
    73

    tested

    How I can get the instance name. I have tested in my environment and I got the next error:

    [DBNETLIB] Sql Server does not exist or access denied
    [DBNETLIB] ConnectionOpen <Connect(())

    As per this result I checked the server name I used typing osql -L. I got the names and used them but with the same result.

    When I open the Sql query analyzer I connect using windows authentication option to connect to my databases.

    Please suggest..

  6. #6
    Join Date
    Mar 2003
    Location
    Indiana, USA
    Posts
    100
    For Windows Security I think you need to use -E option instead of -U and -P options.

    Tim S

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •