Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Running a Sqlcmd commend from a Remote Machine
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

marjan.sayyad
Starting Member

USA
15 Posts

Posted - 12/18/2013 :  18:30:29  Show Profile  Reply with Quote
Hello everybody, I am trying to do this command :
sqlcmd -S servername\instancename,1433 -E -d dbname -i c:\mypath\myscript.sql -o c:\mypath\myoutput.txt
and inside input file I put an easy select query, and this command works on the local machine, but when I run this command from a remoe machine, all the time I get bellow error:
sqlcmd: Error: Error occurred while opening or operating on file c:\mypath\myscript.sql ( Reason: The system cannot the path specified ) any help would be appreciated. Thanks

Mp

khtan
In (Som, Ni, Yak)

Singapore
17689 Posts

Posted - 12/18/2013 :  21:54:42  Show Profile  Reply with Quote
does myscript.sql existed in c:\mypath of the remote machine ?

make sure myscript.sql existed in the remote machine and specify the correct path


KH
Time is always against us

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 12/19/2013 :  03:22:09  Show Profile  Reply with Quote
quote:
Originally posted by marjan.sayyad

Hello everybody, I am trying to do this command :
sqlcmd -S servername\instancename,1433 -E -d dbname -i c:\mypath\myscript.sql -o c:\mypath\myoutput.txt
and inside input file I put an easy select query, and this command works on the local machine, but when I run this command from a remoe machine, all the time I get bellow error:
sqlcmd: Error: Error occurred while opening or operating on file c:\mypath\myscript.sql ( Reason: The system cannot the path specified ) any help would be appreciated. Thanks

Mp


Two things
check if path exists within machine where script is run. If path is actually a path in your local machine then use UNC path \machinename \... or \\ipaddress\...
2. Make location shared giving access to account executing sqlcmd

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

marjan.sayyad
Starting Member

USA
15 Posts

Posted - 12/19/2013 :  17:28:00  Show Profile  Reply with Quote
When I added ip address like you said I got the bellow error either when I run it from local server or from remote machine:
sqlcmd: Error: Error occurred while opening or operating on file c:\mypath\myscript.sql ( Reason: The system cannot the path specified )
Let me explain a little mor about my problem:
-I Do not have sel server on the remore machine. I just have sql server on my local server.
-I put sqlcmd commant on a batch file on the c drive of local server, and batch file works when I do not add ip address in my command.
- because I wanted to know the problem I did that:
on the command line of the remote machine I typted:
\\servername\c$ then I have full access to c drive , but when I run batch file I get this error. I do not know why??? because it works when I run the same batch file on the local server.
Please give me a solution






quote:
Originally posted by visakh16

quote:
Originally posted by marjan.sayyad

Hello everybody, I am trying to do this command :
sqlcmd -S servername\instancename,1433 -E -d dbname -i c:\mypath\myscript.sql -o c:\mypath\myoutput.txt
and inside input file I put an easy select query, and this command works on the local machine, but when I run this command from a remoe machine, all the time I get bellow error:
sqlcmd: Error: Error occurred while opening or operating on file c:\mypath\myscript.sql ( Reason: The system cannot the path specified ) any help would be appreciated. Thanks

Mp


Two things
check if path exists within machine where script is run. If path is actually a path in your local machine then use UNC path \machinename \... or \\ipaddress\...
2. Make location shared giving access to account executing sqlcmd

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs




Mp
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17689 Posts

Posted - 12/19/2013 :  21:18:09  Show Profile  Reply with Quote
can you show us the exact command you used in the remote machine ?


KH
Time is always against us

Go to Top of Page

marjan.sayyad
Starting Member

USA
15 Posts

Posted - 12/20/2013 :  11:44:16  Show Profile  Reply with Quote
sqlcmd -S servername\instancename,1433 -E -d dbname -i c:\mypath\myscript.sql -o c:\mypath\myoutput.txt
these paths exit on the server. On my pc on the command line I type: \\servername\c$ then run the same command on batch file ,and I get that error
Thanks for your help!!!

Mp
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2019 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000