xp-cmdshell

SQL 2012 bcp call returns SQLState = 28000. NativeError = 18456 Login failed for user

非 Y 不嫁゛ 提交于 2019-12-12 16:22:42
问题 I’m working with a SQL stored procedure that makes a call to xp_cmdshell. xp_cmdshell has been enabled, and has a proxy account set to ‘vpexporter’. This sproc was designed to write out a data file to disk. This sproc had been working when it was on a SQL 2005 server. The environment has been upgraded to SQL 2012 and the sproc no longer runs. The line making the call is: set @sql1 = 'bcp "SELECT * FROM dbo.udPayrollOutput" queryout "D:\Repository\Exports\' + @fileunique -Uvpexporter

Could not load file or assembly 'System.Data.DataSetExtensions, Version=3.5.0.0

穿精又带淫゛_ 提交于 2019-12-11 12:35:21
问题 I have a C# Console Application that uses System.Data.DataSetExtensions that I can run smoothly on the client's server through the command line. The only thing I did was to copy the bin/Release directory contents to a specific directory on the server and run the app through the cmd. Now, I want to run the same app through an SQL SERVER Job. I've tried both the CmdExec and T-SQL options, the latest using xp_cmdshell . I've also tried running the program without the job, just with the xp

using BCP to export stored procedure result in SQL Server 2008

六月ゝ 毕业季﹏ 提交于 2019-12-08 05:45:30
问题 Heyy, I'm trying to use BCP to export a SP result to a text file using this query: EXEC xp_cmdshell 'bcp "exec asmary..usp_Contract_SelectByEmpId -1,1" queryout "C:\test.txt" -w -C OEM -t$ -T -r ~ -S heba\HEBADREAMNET ' The output of this query is telling this error: Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near the keyword 'where'. even thought I'm sure that the stored procedure "usp_Contract_SelectByEmpId" is working correctly. Anyone faced that kind of

Get file contents via xp_cmdshell

☆樱花仙子☆ 提交于 2019-12-04 16:52:26
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? 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 FileRead ( content VARBINARY(MAX) ) BULK INSERT FileRead FROM [FilePath] This requires SQL Server to have access

Write to file with xp_cmdshell in UTF-8

岁酱吖の 提交于 2019-12-04 16:38:55
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? 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 Query" -W -w 4000 -s ";" -f 65001 the switch -f 65001 indicate to use UTF8 as outfile file SELECT @command =

How do I check if a directory exists using SQL Server? [closed]

烂漫一生 提交于 2019-11-30 17:41:11
I know this command will create a directory: EXEC master.sys.xp_create_subdir 'C:\testing\' But how do I check whether 'C:\testing\' exists? IF EXISTS(... CREATE TABLE ResultSet (Directory varchar(200)) INSERT INTO ResultSet EXEC master.dbo.xp_subdirs 'c:\' Select * FROM ResultSet where Directory = 'testing' Will return a list of sub directories, you can then check the contents of the list. 来源: https://stackoverflow.com/questions/13765911/how-do-i-check-if-a-directory-exists-using-sql-server

Reading a text file with SQL Server

℡╲_俬逩灬. 提交于 2019-11-30 11:37:40
问题 I am trying to read in a text file from an SQL query (SQL Server 2005) but am not having any luck at all. I've tried various things with EXEC and xp_cmdshell, but all aren't working. This is the general way I've tried to approach this: CREATE TABLE temp (data varchar(2000)); INSERT temp EXEC master.dbo.xp_cmdshell 'type file.txt'; I then try to select data from the temp table. I've searched around a lot and I can't tell what I'm getting wrong. Help? 回答1: What does your text file look like??

How do I check if a directory exists using SQL Server? [closed]

て烟熏妆下的殇ゞ 提交于 2019-11-30 01:32:52
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I know this command will create a directory: EXEC master.sys.xp_create_subdir 'C:\testing\' But how do I check whether 'C:\testing\'

Reading a text file with SQL Server

烈酒焚心 提交于 2019-11-30 01:24:31
I am trying to read in a text file from an SQL query (SQL Server 2005) but am not having any luck at all. I've tried various things with EXEC and xp_cmdshell, but all aren't working. This is the general way I've tried to approach this: CREATE TABLE temp (data varchar(2000)); INSERT temp EXEC master.dbo.xp_cmdshell 'type file.txt'; I then try to select data from the temp table. I've searched around a lot and I can't tell what I'm getting wrong. Help? What does your text file look like?? Each line a record? You'll have to check out the BULK INSERT statement - that should look something like:

Get Results from XP_CMDSHELL

寵の児 提交于 2019-11-27 17:41:12
问题 I have been searching the web some and it seems like the only way to get the results from XP_CMDSHELL is to store them into a temp table. Is there really no easier way? From Experts Exchange: No, xp_cmdshell will not return any information from the exe. and you have to use the following syntax if you are not in the master database to run it. master..xp_cmdshell. You will have to give your user permission to execute this procedure in the master database. You will have to have your exe insert