xp-cmdshell

How to combine stored procedure and select query result?

故事扮演 提交于 2020-01-14 14:06:01
问题 I am trying to combine the results of xp_cmdshell with a select query. I have tried union & read about creating a temp table, but as my result will be having only 1 column. To be more precise i need a smaller query to combine the results of xp_cmdshell with select query as am trying to use it in union based sql injection For example: Select name from employee union exec xp_cmdshell 'whoami' I know this wont work but somewhat similar would be great :) 回答1: Create a temp table and do insert

Which account is used when executing xp_cmdshell 'wmic … “java -jar …”'

流过昼夜 提交于 2020-01-05 04:21:11
问题 I have a jar file that I want to run as a step in an SQL Job . However, the jar file has to run on machineA but the SQL job is schedule on serverA . To make this possible, in serverA's SQL job, I use xp_cmdshell to issue a wmic command to the terminal. xp_cmdshell permits me to issue a terminal command from an T-SQL script wmic permits me to issue a terminal command to machine (in this case a java -jar command) Below is the command I use EXEC master..xp_cmdshell 'wmic /user:mydomain\myuser

permission was denied on the object xp_cmdshell

匆匆过客 提交于 2020-01-05 03:55:09
问题 I am getting Execute permission was denied on the object 'xp_cmdshell'. Here's the situation, I have a stored procedure called ExportFile. I am calling the stored procedure via SqlCommand from a web application from a Virtual PC.. during the execution of this command i get permission error Then I debug it via SQL profiler and execute the result from the profiler to a query window (this means i run the StoredProcedure with the necessary parameters basing from the profiler to a Query window)

Write to file with xp_cmdshell in UTF-8

拜拜、爱过 提交于 2020-01-01 17:27:36
问题 I am creating files with xp_cmdshell like this: SELECT @command = 'echo ' + @fileContent + ' > e:\out\' + @fileName + '.csv' exec master.dbo.xp_cmdshell 'mkdir "e:\out\"' exec master..xp_cmdshell @command The problem is that the file contents is not in UTF-8 and so some special characters are wrong. Can i create the file in UTF-8 encoding? 回答1: You can use the SQLCMD instead the old tecnique as DOS outupt redirect sqlcmd -S ServerName -d DataBaseName -E -o "CSV File Path & Location" -Q "Your

Can a SSIS package called using xp_cmdshell enlist in a SQL Server transaction?

早过忘川 提交于 2019-12-24 08:07:57
问题 I have a very basic SSIS package with one data flow task (from an OLE DB Source to a Flat File). The TransactionOption property is set to Required and I have tried the IsolationLevel option set to ReadCommitted, ReadUncommitted and Serializable. The package exports all rows from a table [TestTable] to the flat file. I have the following SQL script (that I'm running in Management Studio for the moment): BEGIN TRANSACTION DELETE FROM [dbo].[TestTable] DECLARE @SsisString VARCHAR(8000) DECLARE

How to delete files on the directory via MS SQL Server

送分小仙女□ 提交于 2019-12-23 09:57:42
问题 I am trying to delete a file from a directory inside windows using the following query, exec xp_cmdshell 'del "C:\root\sfd_devtracker\'+@deletefile + '"'; When i execute this command it gives the following error, Incorrect syntax near '+'. In @deletefile variable i have the filename which i have to delete. What have i done wrong here? 回答1: xp_cmdshell requires that a literal string be passed as parameter. You cannot construct a value on the fly. Try this: DECLARE @cmd NVARCHAR(MAX) = 'xp

Get file contents via xp_cmdshell

倾然丶 夕夏残阳落幕 提交于 2019-12-21 22:09:50
问题 Is there way to get file from windows xp command prompt? I tried to run xp_cmdshell 'type [path to file]' but then when i insert theese data into other file and renaming it to file.exe (that is executable) it does not work. Any suggestions how to get file contents in such way that i can use it? 回答1: You could use BULK INSERT on the file and treat the file as a table with one row and one column. This should allow you to read the file directly into a VARBINARY field Like this: CREATE TABLE

Getting execute permission to xp_cmdshell

安稳与你 提交于 2019-12-17 07:17:27
问题 I am seeing an error message when trying to execute xp_cmdshell from within a stored procedure. xp_cmdshell is enabled on the instance. And the execute permission was granted to my user, but I am still seeing the exception. The EXECUTE permission was denied on the object ‘xp_cmdshell’, database ‘mssqlsystemresource’, schema ‘sys’ Part of the issue is that this is a shared cluster, and we have a single database on the instance, so we don't have a full range of admin permissions. So I can't go

xp_cmdshell Query Length Too Large

折月煮酒 提交于 2019-12-13 00:41:37
问题 All, I need to write a data set from a large SQL table to a .txt file. To do this I have chosen to use xp_cmdshell. The query I have been using to create the Data.txt file is declare @sql varchar(8000) select @sql = 'bcp "SELECT /*Lots of field names here*/ ' + 'FROM [SomeDatabase]..TableName WHERE /*Some Long Where Clause*/" ' + 'queryout "M:\\SomeDir\\SomeOtherDirectory\\Data.txt" -c -t -T -S' + @@servername exec master..xp_cmdshell @sql the problem I am having is that the SELECT query I am

Passing variable into xp_cmdshell

岁酱吖の 提交于 2019-12-12 16:30:03
问题 I have a stored procedure in SQL Server that checks for today's backup files (files that has a date in its filename). After checks, it will move on to robocopy these files to another folder. The challenge: In this folder, there could be files from yesterday's or other dates. But only today's bak files are required for transfer. --@day allows me to capture the day of a month declare @day char(2) set @day = RIGHT('00' + CONVERT(NVARCHAR(2),DATEPART(DAY,GETDATE())),2) --print @day --In "MyFolder