osql output to txt file on local station

  • All,

    When i'm running an osql command to output to a txt file, the file is writen to the server itself. Is there a way to direct it to a workstation iso the sql server?

    Thanks

  • Yep... write to a UNC instead of a file/path...

    \\machinename\path

    The server must have write privs, as well.

     

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • Is there a way to simulate the "query analyzer" result options where you can choose to have the result send to a file. This way i d'ont need to tamper with sercurity and access rights.

    I'm doing my devlopment from a workstation as well and "query analizer" saves the result file to my workstation. I would like to do the same from a tsql command.

    Any solution?

    Thanks

    Serge

     

     

  • On which machine do you run your osql command?

    _____________
    Code for TallyGenerator

  • On may local workstation.

    this command :

    DECLARE @cmd VARCHAR(255)

    SET @cmd = 'osql -E /Q "SELECT GETDATE()" /o \\AS-B-CLI-000\c:\temp\test2.csv'

    EXEC master..xp_cmdshell @cmd

    will generate error:

    output

    Cannot open output file - \\AS-B-CLI-000\c:\temp\test2.csv

    No such file or directory

    being "AS-b-CLI-000" my worksation. Reason for error is propably access rights as you mentioned before.

    When a leave the workstationpath out of the command the file is writen on the sql server.

    I hope this makes thing clearer.

    Serge

  • So, you run the command on server. In server environment. With all its sequrity rights.

    And what you expect?

    What you are trying to do is calling your local town phone number being in another town ot even in another country.

    Want to call you town - dial long distance access code, that means set rights to access your local folder from server.

    Don't wanna mess with codes - go to your town and make your call, that means run osql command from your local machine. But because you need to retrieve data from server you need to have rights to access SQL server from your local machine.

     

    And where did you see such kind of file reference: \\AS-B-CLI-000\c:\temp\test2.csv ?

    I'm afraid it not gonna work in any way in any environment.

    _____________
    Code for TallyGenerator

  • \\AS-B-CLI-000\c:\temp\test2.csv is an invalid UNC name

    you need to replace the c: with a share name

    eg \\AS-B-CLI-000\mysharename\temp\test2.csv

    but SQL will require the neccessary rights to the share

    You could use c$, which is a hidden share but is restricted to Administrators

    Far away is close at hand in the images of elsewhere.
    Anon.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply