Sql Server xp_cmdshell Access is denied - sql

i'm trying to run some cmd commands via sql query xp_cmdshell
all was working fine but when i have tried to run this code :
EXEC xp_cmdshell 'net user Test Test2 /ADD'
i found this bad result:
System error 5 has occurred.
NULL
Access is denied.
NULL
NULL
can any one help me ?
sry for my bad english

You don't have permission to run this, instead, speak to your Database administrator.

Run your Command Prompt with Administrative Rights by right click on the shortcut, and Run as Administrator.

Related

xp_cmdshell throwing 'null' but working in command prompt

I am using xp_cmdshell command to process csv file to a folder. My query is as below:
Exec master..xp_cmdshell 'C:\test\mydotnetapp.exe -s:03/09/2020 -t:1 -l:1,2,3,4,7 -d C:\test'
In SSMS this command returns null. But in command prompt when I do:
cd C:\test
mydotnetapp.exe -s:03/09/2020 -t:1 -l:1,2,3,4,7 -d C:\test
The same query is working perfectly fine. A couple of things:
xp_cmdshell is enabled
SQL Server has access to the folder
Only this xp_cmdshell command is not working. my other xp_cmdshell is working fine
Any help on how this can be fixed?
If this is run as part of a SQL Job regularly scheduled, run it as a task outside of SQL Server.
Many production DBAs won't let any process run XP_CMDSHELL given the security issues.
If the CSV is well-formed, it can be mapped into SQL Server as a table (not recommended).
It can be imported directly into SQL Server.
Lastly, many production DBAs won't install any custom process code on a production SQL Server machine. The SQL Server machine is dedicated to running only SQL Server plus the minimum extra needed for security and monitoring.

postgres command line script not working on windows 2012 R2 Server but does work on Linux/Mac

The following PSQL command works on Mac/Linux:
psql "dbname='public' user='myuser' password='XXXXXX' host='some.host.com' port='5432'" --file=permissions.sql
But when I try to use the same command on windows, it will login but not execute permissions.sql. I tried changing permissions.sql to \dbbackup\permissions.sql so that I would specify the the full path to the sql script. That didn't appear to help.
When I run the command in Linux, psql logs into the db and executes the script. The same command logs me in to the db but doesn't execute. I just get a command prompt like this: DATABASENAME=>
Then I have to execute \q to logout.
Any suggestions are greatly appreciated.

SQL Server Database Project: Why is command execute not supported

I am trying to copy a file in my Pre Deployment script for a Visual Studio SQL Database project.
:!!copy $(DataFileDirectory)\data.csv $(DataDestinationDirectory)
I found that this generated the error:
SQL72007: The syntax check failed 'Incorrect syntax near .' in the batch near: ':!!copy
So I tried to simplify my testing and tried:
:!! dir
This also failed:
SQL72007: The syntax check failed 'Incorrect syntax near .' in the batch near: ':!! dir
It fails when I try:
!! dir
I am able to execute commands like:
:r .\myfile.sql
I noticed the following error occurs whenever I do :!!,
72006: Fatal scripting error: Command Execute is not supported.
Why is command execute (:!!) not supported?!
This can, of course, only truly be answered by the designers of SSDT, but you can make an educated guess: it would compromise system security too much. It would allow you to run arbitrary commands on the database server's OS, under the account of the user that runs SQL Server itself.
The sqlcmd.exe command allows one to disable the :!! and :ed commands, using the -X command line option, for the same reason.
If you really need to run OS commands in your script, you could still fallback to xp_cmdshell, which of course also has issues, but at least the server's administrator can decide if it should be allowed.
There are a lot more SQLCMD syntax options, that SSDT pre- or post deployment scripts do not support (for example :connect or :on error, it seems). So, another explanation would be, that for the purpose of deployment scripts the :r and :setvar commands were considered sufficient.

How to Execute SVN Update command through SQL xp_CMDShell

I have installed Tortoise SVN on my machine, i want to update my local copy with SVN using SVN UPDATE command. I am using SQL script
EXEC master..xp_CMDShell 'svn update D:\SVN_WorkingFolder'
This script is not executing. May i know where i am doing workng.
Thanks in advances guys.
KumaR
Script execution process won't complete because of insufficient permissions to access network.
We won't get any error message or output redirection.
Steps to give permission: Services--> SQLServer2005--> Properties-->Log on-->This account--> Provide local user credentials. Now restart SQL server then execute above SVN update command it will work. Even we can execute batch file to do this job.

pgadmin crash when click SQL query button

I installed pgAdmin 3 on my windows 64bit system, when I connect to some server, click on the SQL button to execute some script, it crashed, i checked the error log, it says
2012-08-05 08:10:00 ERROR : ERROR: permission denied to create extension "adminpack"
HINT: Must be superuser to create this extension.
Can you help me to solve this problem? thanks!
adminpack is an optional extension. pgAdmin should definitely not crash if you don't have it installed.
You can try to install it manually. In PostgreSQL 9.1 run once in one of your databases:
CREATE EXTENSION adminpack;
You must be superuser for that. Normally the database user postgres is superuser.