Run .exe file from SQL Query - sql

i am trying to open a .exe file from within an sql query or Job.
im using xp_cmdshell , it is enabled on the server
the .exe runs properly when i double click on it from my windows Explorer
but when i try to open it using xp_cmdshell it returns to me 1 row affected
and the row is null.
the .exe file is supposed to delete all the content from a certain table.
when i run the file from the windows explorer, the .exe deletes all the content of the above mentioned table, whereas when i try using xp_cmdshell the content of the table remain intact, which means the .exe file is not opened.
any ideas?? this is the code i'm using
exec master..xp_cmdshell 'C:\inetpub\wwwroot\Digital_Library_Shamaa\ShamaaConsoleIndexer\Publish\setup.exe'
i have added the permission Everyone to the folder containing the above .exe file and all its sub folders!

1) Run EXEC master..xp_cmdshell 'whoami' to see which user you're trying to run the exe file
2) Did you enable :
USE master
GO
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE WITH OVERRIDE
GO
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE WITH OVERRIDE
GO
3) Did you unblock the file ?

Related

trying to understand xp_cmdShell

I know how to use xp_cmdshell to get a listing of a local directory.
The statement below gives me a list of cvs files in the dir C:\TEST.
I ran the statement in my locally installed SSMS.
EXEC Master..xp_cmdShell 'dir C:\TEST\*.csv /b'
However,
EXEC Master..xp_cmdShell 'dir \\ip-adress\share\folder\*.csv /b'
returns a 'No access'.
But running dir \\ip-adress\share\folder\*.csv /b in my commandshell does return a listing. Apparantly I as a user have sufficient rights. Then why does xp_cmdShell return a 'access denied' ?
Is xp_cmdSHell unusable with shares or has this to do with the account that issues the command? But if I started SSMS locally, should the command not run locally under my WIndowsaccount? Same as in commandshell?
I used a SSIS proxy based on my own credentials but it looks like the machine on which the SQL Server is running, is blocked from accessing that share

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.

Issues in importing SQL Server .bacpac file

I am trying to importing a .bacpac of Azure DB into a locally running SQL Server 2017 Enterprise edition.
SQL Server is throwing the following error. I wonder if somebody could help. Thank you in advance.
Could not import package.
Warning SQL72012: The object [xxxxenter image description here-insights_Data] exists in the target, but it will not be dropped even though you selected the 'Generate drop statements for objects that are in the target database but that are not in the source' check box.
Warning SQL72012: The object [2pointb-testing-insights_Log] exists in the target, but it will not be dropped even though you selected the 'Generate drop statements for objects that are in the target database but that are not in the source' check box.
Error SQL72014: .Net SqlClient Data Provider:
Msg 10343, Level 14, State 1, Line 1
CREATE or ALTER ASSEMBLY for assembly 'GroupConcat' with the SAFE or EXTERNAL_ACCESS option failed because the 'clr strict security' option of sp_configure is set to 1. Microsoft recommends that you sign the assembly with a certificate or asymmetric key that has a corresponding login with UNSAFE ASSEMBLY permission. Alternatively, you can trust the assembly using sp_add_trusted_assembly.
Error SQL72045: Script execution error. The executed script:
CREATE ASSEMBLY [GroupConcat]
AUTHORIZATION [dbo]
FROM 0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C01030058898C510000000000000000E00002210B010B00001E000000080000000000007E3D0000002000000040000000000010002000000002000004000000000000000400000000000000008000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000243D000057000000004000003804000000000000000000000000000000000000006000000C00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E74657874000000841D000000200000001E000000020000000000000000000000000000200000602E7273726300000038040000004000000006000000200000000000000000000000000000400000402E72656C6F6300000C000000006000000002000000260
(Microsoft.SqlServer.Dac)
The following script worked for me:
EXEC sp_configure 'show advanced options',1;
GO
RECONFIGURE;
GO
EXEC sp_configure 'clr strict security',0;
GO
RECONFIGURE;
GO

How to save txt File created by BCP command on different server?

I have created text file using following command on the server where database resides
EXEC master.dbo.sp_configure 'show advanced options', 1
RECONFIGURE EXEC master.dbo.sp_configure 'xp_cmdshell', 1
RECONFIGURE EXEC xp_cmdshell 'bcp "SELECT top 10 macnum, Cus_name,Cus_Email FROM [VBOS_TSP].[dbo].[Cust_file]" queryout "d:\creatFile.txt" -T -c'
But I need to create that text file on another machine. As I don't want to save that text file on production. Please suggest me other way so that by passing Path and/or passing credentials of a particular server. How to generate that file on other server?
The path in the other machine should be shared path and accessible from this machine and should have full permissions for the folder to read/write.
I worked on similar scenario and below code format works for me. Try it once after give permissions
#LV_FILE_PATH='\\192.168.1.105\Folder\creatFile.txt'
#LV_SQLTXT='"SELECT top 10 macnum, Cus_name,Cus_Email FROM [VBOS_TSP].[dbo].[Cust_file]"'
SET #LV_CMDTXT = 'BCP ' + #LV_SQLTXT + ' QUERYOUT "' + #LV_FILE_PATH + '" -c -U -T -S -r\n'
EXEC MASTER..XP_CMDSHELL #LV_CMDTXT
You can't use an unc path for queryout at bcp. You're only solution is to export it on the current machine and copy it afterwards.
Another idea is to run bcp on the remote maschine and connect to your datastore to export the data by using the parameter -S.
I hope this helps you.

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.