Solved

BCP error

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server: SNAPSHOT replication to include a newly added table. 2 29
SYbase 4 31
convert null in sql server 12 34
How to search for strings inside db views 4 28
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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