Solved

BCP error

Posted on 2014-04-20
4
401 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 32

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 32

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

'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 …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

22 Experts available now in Live!

Get 1:1 Help Now