I have this program that I want to invoke from SQLServer funny thing is I can invoke this from command line but could not get it to work via 'xp_cmdshell' on this particular server. When I invoke run the following from SQLServer Query Analyser I always get 'NULL' returned. I tried just running EXEC master..xp_cmdshell 'dir ' and it worked, so I am certain it is not a SQL rights problem.
FYI, I executed the same code on another machine and it worked. I just cannot figure out why it is not working on this one server? Can anyone help? thanks
I have created the following trigger:CREATE TRIGGER [CreateFile] ON OutputTableFOR INSERTASDeclare @filename nvarchar(35)Declare @filecontents nvarchar(2000)Declare @strcmdshell varchar(150)SELECT @filecontents = OutputText FROM INSERTEDSELECT @filename = 'c:' + OutputFileName FROM INSERTEDSELECT @strcmdshell = 'echo '+ @filecontents+ ' >'+ @filenameexec master..xp_cmdshell @strcmdshellIt works fine as long as the column OutputText has no carriagereturns.I have used my Access2K front end to dump about ten lines of text intoOutputText, each line broken by vbcrlf so that OutputText looks like:line1testline2textline3textetc.The trigger won't fire with this text.Is there something I can do to remedy this?lq
I have a package that I have been attempting to return a error code after the stored procedure executes, otherwise the package works great.
I call the stored procedure from a Execute SQL Task (execute Marketing_extract_history_load_test ?, ? OUTPUT) The sql task rowset is set to NONE. It is a OLEB connection.
I have two parameters mapped:
tablename input varchar 0 (this variable is set earlier in a foreach loop) ADO. returnvalue output long 1
I set the breakpoint and see the values change, but I have a OnFailure conditon set if it returns a failure. The failure is ignored and the package completes. No quite what I wanted.
The first part of the sp is below and I set the value @i and return.
Why is it not capturing and setting the error and execute my OnFailure code? I have tried setting one of my parameter mappings to returnvalue with no success.
This is my function, it returns SQLDataReader to DATALIST control. How to return page number with the SQLDataReader set ? sql server 2005, asp.net 2.0
Function get_all_events() As SqlDataReader Dim myConnection As New SqlConnection(ConfigurationManager.AppSettings("...........")) Dim myCommand As New SqlCommand("EVENTS_LIST_BY_REGION_ALL", myConnection) myCommand.CommandType = CommandType.StoredProcedure
Dim parameterState As New SqlParameter("@State", SqlDbType.VarChar, 2) parameterState.Value = Request.Params("State") myCommand.Parameters.Add(parameterState)
Dim parameterPagesize As New SqlParameter("@pagesize", SqlDbType.Int, 4) parameterPagesize.Value = 20 myCommand.Parameters.Add(parameterPagesize)
Dim parameterPagenum As New SqlParameter("@pageNum", SqlDbType.Int, 4) parameterPagenum.Value = pn1.SelectedPage myCommand.Parameters.Add(parameterPagenum)
Dim parameterPageCount As New SqlParameter("@pagecount", SqlDbType.Int, 4) parameterPageCount.Direction = ParameterDirection.ReturnValue myCommand.Parameters.Add(parameterPageCount)
myConnection.Open() 'myCommand.ExecuteReader(CommandBehavior.CloseConnection) 'pages = CType(myCommand.Parameters("@pagecount").Value, Integer) Return myCommand.ExecuteReader(CommandBehavior.CloseConnection) End Function
Variable Pages is global integer.
This is what i am calling DataList1.DataSource = get_all_events() DataList1.DataBind()
How to return records and also the return value of pagecount ? i tried many options, nothing work. Please help !!. I am struck
I'm trying to create a report that's based on a SQL-2005 Stored Procedure.
I added the Report Designer, a Report dataset ( based on a shared datasource).
When I try to build the project in BIDS, I get an error. The error occurs three times, once for each parameter on the stored procedure.
I'll only reproduce one instance of the error for the sake of brevity.
[rsCompilerErrorInExpression] The Value expression for the query parameter 'UserID' contains an error : [BC30654] 'Return' statement in a Function, Get, or Operator must return a value.
I've searched on this error and it looks like it's a Visual Basic error :
I am trying to bring my stored proc's into the 21st century with try catch and the output clause. In the past I have returned info like the new timestamp, the new identity (if an insert sproc), username with output params and a return value as well. I have checked if error is a concurrency violation(I check if @@rowcount is 0 and if so my return value is a special number.)
I have used the old goto method for trapping errors committing or rolling back the transaction.
Now I want to use the try,catch with transactions. This is easy enough but how do I do what I had done before?
I get an error returning the new timestamp in the Output clause (tstamp is my timestamp field -- so I am using inserted.tstamp).
Plus how do I check for concerrency error. Is it the same as before and if so would the check of @@rowcount be in the catch section?
So how to return timestamp and a return value and how to check for concurrency all in the try/catch.
by the way I read that you could not return an identity in the output clause but I had no problem.
i have using BCP to output SP return data into txt file, however, when it return nothing , it give SQLException like "no rows affected" , i have try to find out the solution , which include put "SET NOCOUNT ON" command before select statement, but it doesn't help :(
anyone know how to handle the problem when SP return no data ?
does anyone know how to execute a FTP command through sql server 7? I am creation a table and need to ftp the result set. I have it currently creation the table, turning it into a CSV txt file and placing it in a directory. I have to then manually ftp the txt file. I want to automate this process but I cant get the FTP command to execute throught the xp_cmdshell. It will work at the DOS prompt though so I know the syntax is correct. Any sugetsions would be appreciated. -Nathan
hi everybody My requirement is, I have to transfer database backup files from one server to another server to take tape backup. Generally in my backup folder there will be 4days backups. I want to schedule a job so that after database backed up, today’s backup file only copied to the other server. I wrote following code, upto xp_cmdshell every thing is working fine. But xp_cmdshell statement is giving error. I have to use variable value with sp_cmdshell. Please give me the solution for this.
declare @year1 as varchar(4),@month1 as varchar(2),@day1 varchar(2),@filename varchar(40) set @year1=ltrim(str(year(getdate()))) if month(getdate())<10 set @month1='0'+ltrim(str(month(getdate()))) else set @month1=ltrim(str(month(getdate()))) if day(getdate())-1 <10 set @day1='0'+ltrim(str(day(getdate())-1)) else set @day1=ltrim(str(day(getdate())-1))
set @filename='EMPTest_db_'+ @year1+@month1+@day1+'*.bak'
I am trying to run a Visual Basic Script using the xp_cmdshell stored procedure. When I try to run the file, the MS Script Debugger application is started.
I run the script like this: "xp_cmdshell 'D:ScriptFilesSpaceMail.vbs'"
I can run it from the DOS prompt successfully, but not from Query Analyzer. Does anyone have any suggestions on how to prevent the MS Script Debugger from running?
I am trying to run bcp with xp_cmdshell inside a trigger. Whenver I update table the server is hanging. It creates the file in specified location but of ZERO size and I cannot delete it unless I stop SQL server service.
The smae code runs from a stored procedure without any problem.
Can you pl tell me if there are any LIMITATIONS with xp_cmdshell and Trigger.
I beleive this is simple question but I have problem using this command
I was trying to delete contents of a temp folder thru TSQL. Correct me if wrong For example xp_cmdshell " del c:emp*.*" This is leading me to prompt 'Are you sure to delete Y/N'. How do I write a command to say Y. I want to schedule this every week. Is there any other way to do this task like using AT command ,etc.
I am trying to use xp_cmdshell --- xp_cmdshell 'dir abcc$'
--- where abc is host name and C$ is shared name
I get the following error message "Logon failure: unknown user name or bad password." I execute the same command at the dos prompt , I get the directory listing
Hi Guys, i am trying to run an .exe file from queryanalyzer for my testing.I am using the following command exec master..xp_Cmdshell 'C:extEXEproject1.exe -SCHEETAH -Uvijay -Pbell' CHEETAH is my server name User :vijay pwd:bell the problem is its running forever in QueryAnalyzer,when i tried to run the same thing from dosprompt its executing fine. Please help me in this thanks for any help
SQL 7.0 I have given a non sa user permissions to run xp_cmdshell via his NT logon. When he runs it and does a "dir" of the server it works. When he trys to do a "dir" of his own machine it comes up with "Logon failure unknown user name or bad password". SQL Agent is running under a domain admin account. I have placed SQLAgentCmdExec in the servers local administrators group. I have de-selected the option from SQLAgent propertiesJob System which restricts non sa users executing CmdExec stuff. I did attempt to Reset Proxy Account and Reset Proxy Password. When I clicked on these it just gave me message that the account and password had successfully been reset without asking me for username, password or domain.
Hello, friends, This is probably not a question for DBA forum, but may be someone knows the answer. In the stored procedure I'm using xp_cmdshell command to copy file from one dir to another. How I can receive any indication what the process succeded? xp_cmdshell return 1 or 0 if the stored procedure was invoked, I would like to receive an indication that the file was copied.
I tried to use the external procddure - xp_cmdshell - to copy a file from a local drive to a network drive, but failed. Yet the attempt succeeded if I tried to copy a file from one place to another in local drive.
It seems that SQL Server 6.5/7.0 did not recognize any network drive. I greatly appreciate your help/assistance and/or any hint(s). Thanks a lot
I was able to run DTS using xp_cmdshell. In my dts I have 3 global variables which I would like to pass. Can I pass a variable values using xp_cmdshell? xp_cmdshell 'DTSRUN /S ServerName /U user/P pass /N "DTS_Name" '
I need to do FTP using a FTP script...here is the syntax that i am using
ftp -s:c: empftpcmd.txt > c: emplog.txt
when i run it thru the command line, log.txt file has the following ================================================== ftp> Connected to 9.999.99.999.
open 9.999.99.999 220-YYYY1 XXX FTP CS V1R2 at XXXXXX.XXXXXX.XXX.COM, 16:55:07 on 2004-06-15. 220 Connection will close if idle for more than 5 minutes. User (9.999.99.999:(none)): 331 Send password please.
230 USERNAME is logged on. Working directory is "USERNAME.". ftp> Invalid command.
ftp> ascii 200 Representation type is Ascii NonPrint ftp> get 'XXX.YYY.ZZZ.ACCOUNT' c: empXXX.YYY.ZZZ.ACCOUNT.txt 200 Port request OK. 125 Sending data set XXX.YYY.ZZZ.ACCOUNT FIXrecfm 22 250 Transfer completed successfully. ftp: 1172544 bytes received in 3.31Seconds 353.82Kbytes/sec.
Where should i read up on using dos commands in conjunction with the xp_cmdshell extended stored procedure.. I need to manipulate file names.... move copy take off ... parts of the filename and replace... them... etc... any good sites or topics... so that I can learn how to do this... thanks... jonathan
I've recently installed SQL Server 2005 and now trying to enable xp_cmdshell through SQL Server 2005 Surface Area Configuration. However, I am getting the following error:
User does not have permission to perform this action. You do not have permission to run the RECONFIGURE statement.
When xp_cmdshell interacts with FTP it doesn't log the FTP return codes.
History: I found Nigel Rivett's T-SQL FTP scripts http://www.nigelrivett.net/ and concatenated them together with some modifications so I could have a process that actually errors when an FTP fails.
The process FTP's a file, disconnects, and then reconnects to do a dir and then select from the returned listing to see if the file name exists.
I wanted to review the initial log from the put and check for a valid FTP return code of 250 that says "Transfer completed successfully"
Log Snippets:
A normal FTP log shows: ftp> put foo 'mainframe.node.structure.foo' 200 Port request OK. 125 Storing data set MAINFRAME.NODE.STRUCTURE.FOO 250 Transfer completed successfully. ftp: 7972888 bytes sent in 99.63Seconds 80.03Kbytes/sec. ftp> quit 221 Quit command received. Goodbye.
xp_cmdshell log shows (with FTP debug on) shows: 7 put foo 'mainframe.node.structure.foo' 8 PORT 10,99,11,16,7,30 9 ---> STOR MAINFRAME.NODE.STRUCTURE.FOO 10 ---> quit 11 QUIT 12 (null)
As you can see, the return codes and some other messages are missing.
I've messed around with various options and can't seem to get any return codes in the log at all.
I need to kill some user session that i get from below query output
xp_cmdshell 'netstat -an | find /i "est"'
output: -
TCP 0.0.0.47:1099 0.0.0.39:139 ESTABLISHED TCP 0.0.0.47:1433 0.0.0.104:2961 ESTABLISHED TCP 0.0.0.47:1433 0.0.0.104:3012 ESTABLISHED TCP 0.0.0.47:1433 0.0.0.39:2915 ESTABLISHED TCP 0.0.0.47:1433 0.0.0.39:3106 ESTABLISHED TCP 0.0.0.47:2007 0.0.0.26:1487 ESTABLISHED TCP 0.0.0.47:2007 0.0.0.79:1139 ESTABLISHED
do we have any command to kill the connected session to my sql except kill spid.
ex: i want to kill the session of IP 0.0.0.79 from my sql server.
Hi .. I want to Write in files or read from files for example i have My_File.txt . i need a syntax and i want to call this syntax in my Store procedure and this syntax write forexample " Hello Word " in My_File.txt . and i want another syntax that read from My_File.txt forexample "Word" from My_File.txt . what are those syntaxes do that ??
Is there any way better than XP_CMDSHELL for writing in or reading from MyFile.txt ??