Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Job is randomly not working and eating resources.

Status
Not open for further replies.

FatalExceptionError

Technical User
Apr 10, 2001
100
US
I have a job that is broken down in multiple steps. It works but randomly one of the steps will fail. This is a step where I query the database itself. I applied the hotfix that was supposed to fix the job scheduler not releasing processes. that helped my cpu resources but I notice memory starts going up.

This is the error I get
Code:
Executed as user: NT AUTHORITY\SYSTEM. DBCC execution completed. If DBCC printed error messages, contact your system administrator. [SQLSTATE 01000] (Message 2528)  OLE DB provider 'MSDASQL' reported an error. [SQLSTATE 42000] (Error 7399)  Driver's SQLSetConnectAttr failed] [SQLSTATE 01000] (Error 7312)  Driver's SQLSetConnectAttr failed] [SQLSTATE 01000] (Error 7312)  System resource exceeded.] [SQLSTATE 01000] (Error 7312)  OLE DB error trace [OLE/DB Provider 'MSDASQL' IDBInitialize::Initialize returned 0x80004005:   ]. [SQLSTATE 01000] (Error 7300).  The step failed.


This is the source code for the procedure called at the failing step. I believe it is the top portion where it locks up as I can't see the bottom portion causing this kind of error. Is something wrong with my cursor or inserts?

FYI Weights is a linked server from a paradox DB. The procedure is below.

Code:
CREATE   PROCEDURE ExtractSPCData
AS

dbcc traceon (7300, 3604)
-- declare variables
declare @file_name varchar(255)
declare @current_date_time varchar(255)
declare @select_statement varchar(400)
declare @bcp_argument varchar(400)
declare @day varchar(5)
declare @month varchar(5)
declare @year varchar(5)
declare @hour varchar(5)
declare @minute varchar(5)
declare @ticket float
declare @truck_id varchar(15)
declare @time_in varchar(7)
declare @time_out varchar(7)
declare @date varchar(50)
declare @gross_unit varchar(2)
declare @container varchar(15)
declare @s_id varchar(15)
declare @day_cast tinyint
declare @hour_cast tinyint
declare @month_cast tinyint
declare @minute_cast tinyint
declare @net float
declare @gross float
declare @truck_wt float
declare @date_time smalldatetime
declare @last_date_read smalldatetime

--==============================================================================================================

SELECT @last_date_read = MAX(date_time) FROM s_info

DECLARE s_data_cursor CURSOR FOR
SELECT ticket, [truck id], [time in], [time out], date, net, gross, [gross unit], container, [s id], tare 
FROM
OPENQUERY(Weights,'Select * from Weights2 UNION ALL Select * from Weights3 UNION ALL Select * from Weights4') 
WHERE CONVERT(SMALLDATETIME, (date+' '+[time in])) > @last_date_read 
and (c = 'sl' or c = 'hl' or c = 'tb' )

if @@ERROR <> 0 GOTO ExitProc

OPEN s_data_cursor

FETCH NEXT FROM s_data_cursor
INTO @ticket, @truck_id, @time_in, @time_out, @date, @net, @gross, @gross_unit, @container, @s_id, @truck_wt 
SET @date_time = CONVERT(SMALLDATETIME, (@date+' '+@time_in))
if @@ERROR <> 0 
begin
CLOSE s_data_cursor
DEALLOCATE s_data_cursor 
GOTO ExitProc
end
WHILE @@FETCH_STATUS = 0
BEGIN
	
	INSERT info(ticket, truck_id, time_in, time_out, date, date_time, net_wt, gross_wt, unit, container, s_id, truck_wt)
	VALUES (@ticket, @truck_id, @time_in, @time_out, @date, @date_time, @net, @gross, @gross_unit, @container, @s_id, @truck_wt)

	if @@ERROR <> 0 
	begin
	CLOSE s_data_cursor
	DEALLOCATE s_data_cursor 
	GOTO ExitProc
	end

	FETCH NEXT FROM s_data_cursor
	INTO @ticket, @truck_id, @time_in, @time_out, @date, @net, @gross, @gross_unit, @container, @s_id, @truck_wt 
	SET @date_time = CONVERT(SMALLDATETIME, (@date+' '+@time_in))

	if @@ERROR <> 0 
	begin
	CLOSE s_data_cursor
	DEALLOCATE s_data_cursor 
	GOTO ExitProc
	end

END

CLOSE s_data_cursor
DEALLOCATE s_data_cursor

--==============================================================================================================

-- get different parts of current date/time
-- this will be used to set the filename
select @hour = DATEPART(hour, GETDATE())
select @minute = DATEPART(minute, GETDATE())
select @month = DATEPART(month, GETDATE()) 
select @day = DATEPART(day, GETDATE()) 
select @year = DATEPART(year, GETDATE()) 

-- casting is done so that comparisons can be 
-- done on the different date parts.
set @day_cast = CAST(@day as tinyint)
set @hour_cast = CAST(@hour as tinyint)
set @month_cast = CAST(@month as tinyint)
set @minute_cast = cast(@minute as tinyint)

-- These if statements add '0' to different parts
-- of the current date.  This is done so that the
-- filename can properly reflect the mmddyyyyhhmm
-- naming convention for numbers truncating the '0'
-- when they are less than 10.
IF @minute_cast < 10
BEGIN
   SET @minute = '0' + @minute
END

IF @month_cast < 10
BEGIN
   SET @month = '0' + @month
END

IF @day_cast < 10
BEGIN
    SET @day = '0' + @day
END

IF @hour_cast < 10
BEGIN
   SET @hour ='0' + @hour
END

-- sets the current_date_time to mmddyyyyhhmm
SET @current_date_time = @month + @day + @year + @hour + @minute

-- removes the : from current_date_time
SET @current_date_time = REPLACE(@current_date_time, ':','')

-- sets the full filename path and extension included.
SET @file_name = 'C:\DBquery\sData\'+ @current_date_time + '.txt'

-- sets the sql query statement
SET @select_statement = 'select * from info where date_time > CONVERT(SMALLDATETIME,'''+CONVERT(varchar(50),@last_date_read,100 )+''') order by date_time" queryout '

-- sets the full BCP command to
SET @bcp_argument = 'bcp "' + @select_statement + ' ' + @file_name + ' -Sapp-bidfax -T -c'


ExitProc:

SET QUOTED_IDENTIFIER OFF 


GO

=======================================
The statement below is true
The statement above is false

There are 10 kinds of people, those who know binary and those who don't
 
Any reason that you are using an OPENQUERY to do this?

Denny
MCSA (2003) / MCDBA (SQL 2000) / MCTS (SQL 2005) / MCITP Database Administrator (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Because Weights is a paradox DB I access using a Linked Server. Is there another way I could hit it?

=======================================
The statement below is true
The statement above is false

There are 10 kinds of people, those who know binary and those who don't
 
You can go directly to it via the linked server instead of using OpenQuery. You'll want to test for performance of course.


Code:
Select * 
from Weights2 
WHERE CONVERT(SMALLDATETIME, (date+' '+[time in])) > @last_date_read 
and (c = 'sl' or c = 'hl' or c = 'tb' )
UNION ALL 
Select * 
from Weights3 
WHERE CONVERT(SMALLDATETIME, (date+' '+[time in])) > @last_date_read 
and (c = 'sl' or c = 'hl' or c = 'tb' )
UNION ALL 
Select * 
from Weights4
WHERE CONVERT(SMALLDATETIME, (date+' '+[time in])) > @last_date_read 
and (c = 'sl' or c = 'hl' or c = 'tb' )

It is possible that the paradox driver is causing the memory leak.

I'm not sure why you are using a cursor since all you are doing is inserting data into a table. Why not do a direct insert from the select statement.

Code:
insert into info
(ticket, truck_id, time_in, time_out, date, date_time, net_wt, gross_wt, unit, container, s_id, truck_wt)

Select ticket, [truck id], [time in], [time out], date, net, gross, [gross unit], container, [s id], tare  
from Weights2 
WHERE CONVERT(SMALLDATETIME, (date+' '+[time in])) > @last_date_read 
and (c = 'sl' or c = 'hl' or c = 'tb' )

UNION ALL 
Select ticket, [truck id], [time in], [time out], date, net, gross, [gross unit], container, [s id], tare 
from Weights3 
WHERE CONVERT(SMALLDATETIME, (date+' '+[time in])) > @last_date_read 
and (c = 'sl' or c = 'hl' or c = 'tb' )

UNION ALL 
Select ticket, [truck id], [time in], [time out], date, net, gross, [gross unit], container, [s id], tare  
from Weights4
WHERE CONVERT(SMALLDATETIME, (date+' '+[time in])) > @last_date_read 
and (c = 'sl' or c = 'hl' or c = 'tb' )

Then do your date time stuff at the end. Cursors will eat up memory and cpu time much more than doing a direct insert.

Denny
MCSA (2003) / MCDBA (SQL 2000) / MCTS (SQL 2005) / MCITP Database Administrator (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
It won't allow me to access the linked server like that. Everything I have read up till now has indicated that I need to use openquery(linked_server,'query string') format.

=======================================
The statement below is true
The statement above is false

There are 10 kinds of people, those who know binary and those who don't
 
You would need to use the four part name instead of just the tables which I should have caught but it should work fine.

I access linked servers all the time using the four part name and it works fine.

Denny
MCSA (2003) / MCDBA (SQL 2000) / MCTS (SQL 2005) / MCITP Database Administrator (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
But definitely elliminate the cursor. The code will run much faster and take way fewer resources. Never use a cursor to do an insert if you can possibly avoid it. I've re-written stufs converting from a cursor to a set-based insert that went from taking hours to milliseconds. I rewote one cursor-based import that took over 24 hours to run that I can now do in less than half an hour.

Questions about posting. See faq183-874
Click here to help with Hurricane Relief
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top