0

I have used sqlcmd to capture the required data from a remote server ,which is coming fine .

I have used the below query in a batch file -

>>"Output_hvac.xls" echo %date% %time%
>>"Output_hvac.xls" SQLCMD ...

Now This batch file is kept on a local machine ,thus when it runs it produces an output _hvac excel file .

I want that this excel file be stored in some other server which is not having sql server installed .The batch has to run on the local machine and the excel sheet to be updated on the server .Now I have access to the server but if i am trying to do this with the following query ,it shows access denied .

>>"//172......./d$/Output_hvac.xls" echo %date% %time%
    >>"Output_hvac.xls" SQLCMD ...

Now how would i do this .

user1896796
  • 731
  • 3
  • 9
  • 25
  • I don't understand the code snippets you've shown. Usually you execute `sqlcmd` with the `-o` option to specify the output path, but I don't see anything like that in what you've shown. And what is the precise error message? If it's Windows error 5 ("Access is denied") then the issue is simply that you don't have permission to write to the share and/or folder that you want to. – Pondlife Apr 09 '13 at 15:38

1 Answers1

0

You need to formally connect to a remote server when you use the sqlcmd command.

Check out the -S argument:

-S [protocol:]server[\instance_name][,port] Specifies the instance of SQL Server to which to connect. It sets the sqlcmd scripting variable SQLCMDSERVER.

Specify server_name to connect to the default instance of SQL Server on that server computer. Specify server_name [ instance_name ] to connect to a named instance of SQL Server on that server computer.

If no server computer is specified, sqlcmd connects to the default instance of SQL Server on the local computer. This option is required when you execute sqlcmd from a remote computer on the network. protocol can be tcp (TCP/IP), lpc (shared memory), or np (named pipes). If you do not specify a server_name [ \instance_name ] when you start sqlcmd, SQL Server checks for and uses the SQLCMDSERVER environment variable.

Full article on msdn.

Community
  • 1
  • 1
Bogdan Gavril MSFT
  • 20,615
  • 10
  • 53
  • 74
  • I didn't get what you are trying to say .Please could be more simple.I have used -S "server name to fetch data from remote server ,that is working fine.I want to fetch from a remote server through a batch file which is on a local machine and give this data to another server machine . – user1896796 Apr 09 '13 at 11:17
  • You need to execute the batch file in the context of a user who has access to those machines. – Bogdan Gavril MSFT Apr 09 '13 at 11:47
  • i have the access to that machine .I can remote login to that machine.But then also if i try that when my batch file runs on the local machine and the excel file on the server machine should get updated .It shows access denied . – user1896796 Apr 09 '13 at 12:09