Delete File in VM Server through SQL Server - sql-server-2014

I tried to delete a file in VM Server by using a SQL Server shell command.
Like:
EXEC xp_cmdshell 'DEL \\DEV-ServerName\c$\TestFileToDelete\test.txt`
Then a get the message:
Access is denied
Please someone can help? This work well with my Windows command prompt

1.) share "testFileToDelete" with SQL Server Service
2.) Run this: EXEC xp_cmdshell 'DEL \DEV-ServerName\TestFileToDelete\test.txt`

Related

MYSQL script doesn't run from command prompt but does from within mysql

Hi I have a script file that when I login to mysql from the command prompt and execute it runs no problem.
the command I issue is
\. test.sql
however from command prompt nothing happens
-usa -p***** -h192.168.0.**** < test.sql
the script says which db to use and then issues a flush tables for export command for all the tables in the db.
I am happy with the syntax that executes from the command prompt as I have a test1.sql that is a simple select this works no problem.
I am on a windows 2008 R2 server and mysql 5.7.15

How to execute .sql files present on windows machine on a remotely connected mysql server?

I have a .sql file on windows that I want to run on mysql server that is present on centOS. I am using the following command to connect and execute the .sql file-
mysql -u user_name -ppassw0rd -h [ip address of centOS] -P [port used
by mysql server] --verbose < file path on windows.
But on executing this command i am getting an error as :
ERROR 2013 (HY000) at line 3: Lost connection to MySQL server during
query
Also is there any way to see the errors that occur when query is executed.
Note - I am using mysql command line tool on windows to run the above command.

How to connect Sqlcmd to the server?

I just installed SQL Server 2008, and I wanted to use the command editor to execute queries.
To do that I opened the command prompt, and I typed
Sqlcmd -S Serverinstance
but I got an error saying :
Named Pipes Provider: Could not open a connection to SQL Server [53].
Sqlcmd : erreur : Microsoft SQL Server Native Client 10.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
Sqlcmd : erreur : Microsoft SQL Server Native Client 10.0 : Login timeout expired
What should I do to get it connected to the server so I can proceed?
Thank you :D.
(This one is going to sounds silly) my problem was that I wasn't using capital 'S'
Eg:
C:\> SQLCMD -S localhost\sqlexpress
You need to either use the integrated-security approach of using your Windows credentials to connect to SQL Server by specifying -E as an option:
C:\> SQLCMD -S Serverinstance -E
or then you need to define a user/password set to achieve a SQL Server login:
C:\> SQLCMD -S Serverinstance -U (login in) -P (password)
All the many SQLCMD parameters are well-documented on MSDN SQL Server Books Online!
The server you are specifying cannot be found or is not accessible. so either the server is wrong (have you spelt it correctly) or you are not specifying it correctly or it is not accessible from your machine.
After you've got that right, you will need to specify a username/password or a -E command qualifier for a Trusted Connection. You may also need to specify the database with a -d qualifier.
You can get help by typing
Sqlcmd -?

Permissions for PSExec run from SQL job

I have the following in a CMDExec type SQL Job step (details changed):
D:\path\PSExec.exe \\servername -accepteula -u "domain\username" -p password D:\path\executable.exe
This works fine.
However, I have set up a proxy in SQL Server for the same user account - which the job is using, so you'd think I wouldn't need the -u and -p arguments.
But if I don't supply them I get the error:
Unhandled Exception: System.Data.SqlClient.SqlException: Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
which is from SQL Server, because the remote executable connects to SQL as the same user context.
Why doesn't this work, and can I make it work without including the credentials in the job detail? (or a batch file, or similar)
Thanks
P.S. The SQL Server connected to by the remote executable is the same one as the job is run in, if it helps!
The reason is because Kerberos is not running!
Thanks to Marc Jellinek on LinkedIn SQLDBA group :)

-S unknown option when using sqlcmd

I get an error when I execute the command below from a DOS window in Windows XP with SQL Server 2008. -S is the option to specify the server name.
error: Sqlcmd: '-S': unknown option.
sqlcmd –S localhost –d databasename -i C:\files\somefile.sql –E
It's working now using '.' as the server name when I typed the line manually.
What I did earlier was type the command in an editor, copied the ine and pasted into the command line. My guess is that an invisible control character got in there during the copy. I opened another dos window and typed a similar command using 'localhost' and it worked. I never used sqlcmd to connect to a server so I thought my syntax was wrong.
localhost, . & (local) should all work and if you use a non existent server name it will complain that it couldn't connect. It shouldn't say -S is not an option.
Is localhost the correct reference to use? Try sqlcmd -L to get the list of servers.
LocalHost is for IIS
(LOCAL) is for SQL Server. Or you can use a period