1

Re: SQL Code Object is Open

I'm running an XML query on our database. I've been attempting to extract all our records (1,063,658 to be exact). I get this error SQL Code: Object is Open. The XML query is fine with smaller amounts of data though these are still actually large amounts - I've just extracted 711,535 records with no problem.

I guess I'm coming up against some kind of restriction. Any ideas?

Graham Hawker
Thames Valley Environmental Records Centre

2

Re: SQL Code Object is Open

Hi Graham
Is the only error information you get "Object is Open"? Also it might be interesting to know what is in your query and how long it takes before this message appears - could it be a timeout?
Best Wishes

John van Breda
Biodiverse IT

3

Re: SQL Code Object is Open

Hi John

The exact statement is "There is an error in the sql code: The error message is "Object is Open""

The query is one written by Mike Weideli and works fine normally - it selects data based on entry date. It only when trying to select all data with this size of database (we have done this for smaller databases with no problem) that this error happens. It comes up after about 15 minutes of thinking time.

I have done a work around whereby I run one query to select data entered after a certain date and another that selects data before a certain date so we can do the full extraction we need in two parts.

Graham Hawker
Thames Valley Environmental Records Centre

4

Re: SQL Code Object is Open

Thanks Graham. I probably need to see a copy of the XML file though to look into it any further.
Best wishes

John van Breda
Biodiverse IT

5

Re: SQL Code Object is Open

Hi was there ever a fix for this? I have the same issues, same symptoms. The XML works well for smaller reports (date restricted) but fails on reporting across the whole database.

Best wishes,

Les Evans-Hill
Senior Data Officer
Butterfly Conservation, Butterflies for the New Millennium and National Moth Recording Scheme

6

Re: SQL Code Object is Open

Hi

Please could you provide the report. I know great deal more now that I did in 2010 so may be able to work out what the problem is.

Mike Weideli

7

Re: SQL Code Object is Open

Hi Mike,

As below - this works perfectly well on a small subset of data i.e. 2016 only, but on a larger subset i.e. 2000-2016 it fails. It worked fine last January on the complete NMRS database. The only software to have changed are MS updates to W2k8R2 and SQL 2008 plus of course R6 updates.

[code]
<?xml version = "1.0" ?>

<!--
                EMILY
                XML Report by Les Hill
                Version 1.0.0 - 13/1/2016
-->
<CustomReport
                title = "EMILY"
                menupath = "My Reports"
                description = "Returns nomenclature, exact abundance (else presence), life stage (excludes records where recorded life stage is not like user choice), specific date (only), grid reference (1km, 2km or 10km) and vice-county name."
>
<SQL>

DECLARE @GRIDSIZE INT

                <Where keytype = "Default">

SET @GRIDSIZE
<Condition field = "" operator = "equal" type = "OptionSet" name = "Square Size">
                <Option name = "1km" value = "1" />
                <Option name = "2km" value = "2" />
                <Option name = "10km" value = "0" />
</Condition>

                                SELECT TLI.LST_ITM_CODE AS [code]
                                ,ITN.ACTUAL_NAME
                                ,ITN.PREFERRED_NAME
                                ,ITN.COMMON_NAME
                                ,CASE WHEN TXD.ACCURACY =  'Exact' THEN TXD.DATA ELSE '0' END AS [Abundance]
                                ,MQ.SHORT_NAME AS [Life Stage]
                                ,dbo.LCReturnVagueDateShort(S.VAGUE_DATE_START, S.VAGUE_DATE_END, 'D') AS Date
                                ,dbo.LCRectifyGR(S.SPATIAL_REF, S.SPATIAL_REF_SYSTEM, @GRIDSIZE) AS [Grid Reference]
                                ,ALOC.ITEM_NAME AS [Vice-county]
                                FROM TAXON_OCCURRENCE AS TOCC
                                LEFT JOIN TAXON_DETERMINATION AS TDET ON TOCC.TAXON_OCCURRENCE_KEY = TDET.TAXON_OCCURRENCE_KEY AND TDET.PREFERRED = 1
                                LEFT JOIN TAXON_OCCURRENCE_DATA AS TXD ON TOCC.TAXON_OCCURRENCE_KEY = TXD.TAXON_OCCURRENCE_KEY
                                LEFT JOIN [SAMPLE] AS S ON TOCC.SAMPLE_KEY = S.SAMPLE_KEY
                                LEFT JOIN MEASUREMENT_QUALIFIER AS MQ ON TXD.MEASUREMENT_QUALIFIER_KEY = MQ.MEASUREMENT_QUALIFIER_KEY
                                LEFT JOIN INDEX_TAXON_NAME AS ITN ON ITN.TAXON_LIST_ITEM_KEY = TDET.TAXON_LIST_ITEM_KEY
                                LEFT JOIN TAXON_LIST_ITEM AS TLI ON ITN.TAXON_LIST_ITEM_KEY = TLI.TAXON_LIST_ITEM_KEY
                                LEFT JOIN LOCATION AS L ON S.LOCATION_KEY  =  L.LOCATION_KEY
                                LEFT JOIN Sample_Admin_Areas SAA ON SAA.Sample_Key = S.Sample_Key
                                LEFT JOIN Survey_Event ON Survey_Event.Survey_Event_Key = S.Survey_Event_Key
                                LEFT JOIN Admin_Area ASam ON ASam.Admin_Area_Key = SAA.Admin_Area_Key
                                LEFT JOIN Location LSurv ON Survey_Event.Location_Key = LSurv.Location_Key
                                LEFT JOIN Survey ON Survey.Survey_Key = Survey_Event.Survey_Key
                                LEFT JOIN Location_Admin_Areas LAA ON LAA.Location_Key = LSurv.Location_Key
                                LEFT JOIN Admin_Area ALOC ON ALOC.Admin_Area_Key = LAA.Admin_Area_Key
                                WHERE <Condition field = "dbo.LCReturnDate(S.VAGUE_DATE_START, S.VAGUE_DATE_TYPE, 'Y')" operator = "greater than equal" type = "Number" name = "Start Year" />
                                AND <Condition field = "dbo.LCReturnDate(S.VAGUE_DATE_START, S.VAGUE_DATE_TYPE, 'Y')" operator = "less than equal" type = "Number" name = "End Year" />
                                AND <Condition field = "MQ.SHORT_NAME" operator = "like" type = "Text" name = "Life stage (like)" />
                                AND <Condition field = "TOCC.VERIFIED" operator = "not equal" type = "OptionSet" name = "Failed/Pending Verification" ><Option name = "Include" value = "3" /><Option name = "Exclude" value = "1" /></Condition>
                                AND <Condition field = "TOCC.CONFIDENTIAL" operator = "less than" type = "OptionSet" name = "Confidential" ><Option name = "Include" value = "2" /><Option name = "Exclude" value = "1" /></Condition>
                                AND <Condition field = "TOCC.CHECKED" operator = "greater than" type = "OptionSet" name = "Unchecked Records" ><Option name = "Include" value = "-1" /><Option name = "Exclude" value = "0" /></Condition>
                                AND <Condition field = "TOCC.ZERO_ABUNDANCE" operator = "less than" type = "OptionSet" name = "Zero Abundance" ><Option name = "Include" value = "2" /><Option name = "Exclude" value = "1" /></Condition>
                                AND S.VAGUE_DATE_TYPE = 'D'
                                ORDER BY ITN.SORT_ORDER

                </Where>
</SQL>
</CustomReport>
[/code]

Les Evans-Hill
Senior Data Officer
Butterfly Conservation, Butterflies for the New Millennium and National Moth Recording Scheme

8

Re: SQL Code Object is Open

It may be a time out problem. Try changing the value as per the attached (say from 600 to 1200). You get to it via Mangement Studio. Right click on the connection then on properties.

Post's attachments

ChangeTimeOut.zip 52.66 kb, 2 downloads since 2016-12-08 

You don't have the permssions to download the attachments of this post.
Mike Weideli

9

Re: SQL Code Object is Open

Hi Mike, I applied the timeout change and it crashed out after about 45 minutes. Shall I increase the timeout or go for the '0' option?

BW

Les Evans-Hill
Senior Data Officer
Butterfly Conservation, Butterflies for the New Millennium and National Moth Recording Scheme

10

Re: SQL Code Object is Open

I think that the query may simply be running out of system resourcss. There are lots of left joins which could be inner joins, which must be impacting on performamce if nothing else.

Mike Weideli

11

Re: SQL Code Object is Open

I believe you may well be right. I'm running some similar code I found via the Management Studio which may be the report I ran previously (I honestly can't remember!) This does split the JOINS between INNER and LEFT and may well be the version that worked. I'll advise either way.

Les Evans-Hill
Senior Data Officer
Butterfly Conservation, Butterflies for the New Millennium and National Moth Recording Scheme

12

Re: SQL Code Object is Open

I have had  a quick go at changing the joins

                                FROM TAXON_OCCURRENCE AS TOCC
                                INNER JOIN TAXON_DETERMINATION AS TDET ON TOCC.TAXON_OCCURRENCE_KEY = TDET.TAXON_OCCURRENCE_KEY AND TDET.PREFERRED = 1
                                LEFT JOIN TAXON_OCCURRENCE_DATA AS TXD ON TOCC.TAXON_OCCURRENCE_KEY = TXD.TAXON_OCCURRENCE_KEY
                                INNER JOIN [SAMPLE] AS S ON TOCC.SAMPLE_KEY = S.SAMPLE_KEY
                                LEFT JOIN MEASUREMENT_QUALIFIER AS MQ ON TXD.MEASUREMENT_QUALIFIER_KEY = MQ.MEASUREMENT_QUALIFIER_KEY
                                INNER JOIN INDEX_TAXON_NAME AS ITN ON ITN.TAXON_LIST_ITEM_KEY = TDET.TAXON_LIST_ITEM_KEY
                                INNER JOIN TAXON_LIST_ITEM AS TLI ON ITN.TAXON_LIST_ITEM_KEY = TLI.TAXON_LIST_ITEM_KEY
                                LEFT JOIN LOCATION AS L ON S.LOCATION_KEY  =  L.LOCATION_KEY
                                LEFT JOIN Sample_Admin_Areas SAA ON SAA.Sample_Key = S.Sample_Key
                                INNER  JOIN Survey_Event ON Survey_Event.Survey_Event_Key = S.Survey_Event_Key
                                LEFT JOIN Admin_Area ASam ON ASam.Admin_Area_Key = SAA.Admin_Area_Key
                                LEFT JOIN Location LSurv ON Survey_Event.Location_Key = LSurv.Location_Key
                                INNER JOIN Survey ON Survey.Survey_Key = Survey_Event.Survey_Key
                                LEFT JOIN Location_Admin_Areas LAA ON LAA.Location_Key = LSurv.Location_Key
                                LEFT JOIN Admin_Area ALOC ON ALOC.Admin_Area_Key = LAA.Admin_Area_Key

Mike Weideli

13

Re: SQL Code Object is Open

The query ran to completion in 66 minutes - your JOINS are very similar to the ones I used in Mgt. Studio. I'll give them a go anyway.

Les Evans-Hill
Senior Data Officer
Butterfly Conservation, Butterflies for the New Millennium and National Moth Recording Scheme