Solved

BCP error

Posted on 2014-04-20
4
413 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 34

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 34

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connect to SQL 2008 r2 server over the Internet 4 85
If in a where clause in t-sql 7 53
UPDATE JOIN multiple tables 5 35
TSQL Assignining CTE column in to a variable 3 27
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…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
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 …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

710 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