Solved

BCP error

Posted on 2014-04-20
4
402 Views
Last Modified: 2014-05-04
Hello,

I have written some script that runs the BCp to execute a stored procedure and output the results to a file.

DECLARE	@return_value int
DECLARE @strbcpcmd NVARCHAR(2000)


set @strbcpcmd = 'bcp "exec [BPSD].[dbo].[SKL_XML_Export_InitialLoad] @StartDate = ''2013-11-01'', @EndDate = ''2014-09-30''" queryout "d:\nasher\bpsd\2013.xml" -w -C OEM -t"$" -T -S -U xxx -P xxxxx'+@@servername
select @strbcpcmd
EXEC master..xp_cmdshell @strbcpcmd

Open in new window



It works fine on my local SQL Server 2012 machine but when i deploy it to the live server (which is SQL Server 2008) i get the following error:

SQLState = 37000, NativeError = 5302
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Mutator 'modify()' on '@Aviseringsinformation' cannot be called on a null value.
NULL

Open in new window


I have looked for this error but can not find any reference to it.  I suspect that it could be a permission error because i can run the sp manually.  Also the second line refers to update a node that does not exist but i know that that it should.
0
Comment
Question by:soozh
  • 2
  • 2
4 Comments
 
LVL 33

Accepted Solution

by:
ste5an earned 500 total points
ID: 40011111
Well, 'it should exist' is a little weak. So add some logging to your procedure around that modify() calls to verify you assumption.
0
 

Author Comment

by:soozh
ID: 40011238
ok. good idea.  how would you write log statements?  I normally just use a select statement... this ok here as well when using the BCP?
0
 
LVL 33

Expert Comment

by:ste5an
ID: 40011260
It is not BCP what I had in mind. You need some logging in your stored procedure. You may use xp_logevent (Transact-SQL) or use your own table and insert logging rows into it. When you use your own table, then you need and table variable and a TRY..CATCH block. Otherwise your log table would be affected by rollbacks. E.g.

USE Test;
GO

CREATE TABLE dbo.Log
(
	LogID INT IDENTITY(1, 1) NOT NULL PRIMARY KEY,
	LogTimeStamp DATETIME NOT NULL,
	LogMessage NVARCHAR(MAX)
);
GO

CREATE PROCEDURE dbo.MySproc
AS
	SET NOCOUNT ON;
	SET XACT_ABORT ON;

	DECLARE @Aviseringsinformation XML; -- What type ever.

	DECLARE @Log TABLE 
	(
		LogTimeStamp DATETIME DEFAULT ( GETDATE() ),
		LogMessage NVARCHAR(MAX)
	);

	INSERT INTO @Log ( LogMessage ) VALUES ( 'Begin..' );

	BEGIN TRY
	    
		-- Your code here. 
		-- Place one or more log inserts around the your statemten containing the modify().
		-- Output also the value of your variable @Aviseringsinformation.
		INSERT INTO @Log ( LogMessage ) VALUES ( '@Aviseringsinformation is ' + CAST( @Aviseringsinformation AS NVARCHAR(MAX)) );
		-- Run here the modify() statement.
		
		INSERT INTO @Log ( LogMessage ) VALUES ( 'Done.' );
	END TRY
	BEGIN CATCH
		-- You may use the ERROR_xxx() functions to get additional information.
		INSERT INTO @Log ( LogMessage ) VALUES ( 'Error.' );
	END CATCH;

	INSERT INTO dbo.Log ( LogTimeStamp, LogMessage)
		SELECT	LogTimeStamp, 
			LogMessage
		FROM	@Log;

Open in new window

0
 

Author Closing Comment

by:soozh
ID: 40040773
You are correct... it did not exist... fixed now!
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
Send secure, cloud-based, encrypted alerts and maintain HIPAA compliant messaging. Integrates priority & secure messaging into one application. Ensures IT, emergency respondents and healthcare professionals that their critical messages are never mis…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now