1

Re: A simple guide to XML reports #2

This second example is only slightly more ambitious. What I'm trying to achieve here is a list of landowners for each location designations (e.g. a "Wildlife Site").
The kit I've used for this is a little better than in my previous posting.
Now I've obtained Access 2003 and linked it to the underlying Recorder database in order to construct a query.
Here's the query I've designed in Access 2003:

SELECT     TOP 100 PERCENT dbo.LOCATION.LOCATION_KEY, dbo.SITE_STATUS.SHORT_NAME AS Status, dbo.LOCATION.FILE_CODE AS Object, 
                      dbo.LOCATION_NAME.ITEM_NAME AS Location, dbo.LOCATION.SPATIAL_REF AS Grid, dbo.TENURE_TYPE.SHORT_NAME AS Tenure, 
                      dbo.INDIVIDUAL.FORENAME AS Initials, dbo.INDIVIDUAL.SURNAME AS Name, dbo.ADDRESS.ADDRESS_1 AS Address, 
                      dbo.CONTACT_NUMBER.NUMBER AS Contact
FROM         dbo.TENURE INNER JOIN
                      dbo.INDIVIDUAL ON dbo.TENURE.OWNED_BY = dbo.INDIVIDUAL.NAME_KEY INNER JOIN
                      dbo.LOCATION_NAME ON dbo.TENURE.LOCATION_KEY = dbo.LOCATION_NAME.LOCATION_KEY INNER JOIN
                      dbo.LOCATION ON dbo.LOCATION_NAME.LOCATION_KEY = dbo.LOCATION.LOCATION_KEY INNER JOIN
                      dbo.TENURE_TYPE ON dbo.TENURE.TENURE_TYPE_KEY = dbo.TENURE_TYPE.TENURE_TYPE_KEY INNER JOIN
                      dbo.ADDRESS ON dbo.INDIVIDUAL.NAME_KEY = dbo.ADDRESS.NAME_KEY INNER JOIN
                      dbo.CONTACT_NUMBER ON dbo.INDIVIDUAL.NAME_KEY = dbo.CONTACT_NUMBER.NAME_KEY INNER JOIN
                      dbo.LOCATION_DESIGNATION ON dbo.LOCATION.LOCATION_KEY = dbo.LOCATION_DESIGNATION.LOCATION_KEY INNER JOIN
                      dbo.SITE_STATUS ON dbo.LOCATION_DESIGNATION.SITE_STATUS_KEY = dbo.SITE_STATUS.SITE_STATUS_KEY
WHERE     (dbo.LOCATION_NAME.PREFERRED = 1) AND (dbo.TENURE_TYPE.SHORT_NAME = 'Owner') AND (dbo.SITE_STATUS.SHORT_NAME = 'Wildlife Site')
ORDER BY dbo.LOCATION_NAME.ITEM_NAME

A little tidying up in a text editor (removing the "Top 100 percent" and the "dbo."s) and I've got something that will insert into my xml document.

SELECT  
    LOCATION.LOCATION_KEY, 
    SITE_STATUS.SHORT_NAME AS Status, 
    LOCATION.FILE_CODE AS Object, 
        LOCATION_NAME.ITEM_NAME AS Location, 
        LOCATION.SPATIAL_REF AS Grid, 
        TENURE_TYPE.SHORT_NAME AS Tenure, 
        INDIVIDUAL.FORENAME AS Initials, 
        INDIVIDUAL.SURNAME AS Name, 
        ADDRESS.ADDRESS_1 AS Address, 
        CONTACT_NUMBER.NUMBER AS Contact
FROM         
    TENURE INNER JOIN
        INDIVIDUAL ON TENURE.OWNED_BY = INDIVIDUAL.NAME_KEY INNER JOIN
        LOCATION_NAME ON TENURE.LOCATION_KEY = LOCATION_NAME.LOCATION_KEY INNER JOIN
        LOCATION ON LOCATION_NAME.LOCATION_KEY = LOCATION.LOCATION_KEY INNER JOIN
        TENURE_TYPE ON TENURE.TENURE_TYPE_KEY = TENURE_TYPE.TENURE_TYPE_KEY INNER JOIN
        ADDRESS ON INDIVIDUAL.NAME_KEY = ADDRESS.NAME_KEY INNER JOIN
        CONTACT_NUMBER ON INDIVIDUAL.NAME_KEY = CONTACT_NUMBER.NAME_KEY INNER JOIN
        LOCATION_DESIGNATION ON LOCATION.LOCATION_KEY = LOCATION_DESIGNATION.LOCATION_KEY INNER JOIN
        SITE_STATUS ON LOCATION_DESIGNATION.SITE_STATUS_KEY = SITE_STATUS.SITE_STATUS_KEY
WHERE     
    (LOCATION_NAME.PREFERRED = 1) AND (TENURE_TYPE.SHORT_NAME = 'Owner') AND (SITE_STATUS.SHORT_NAME = 'Wildlife Site')
ORDER BY 
    LOCATION_NAME.ITEM_NAME

Here's the final xml document after I've dropped the above code in:

<?xml version="1.0" ?> 
<CustomReport menupath="Location Reports" title="Location ownership (Individuals)" description="Generates a list of location owners for specified location status."> 
<SQL>
<Where keytype="Default">
SELECT     
    LOCATION.LOCATION_KEY, 
    TENURE_TYPE.SHORT_NAME AS Tenure, 
    LOCATION_NAME.PREFERRED as Preferred,
        LOCATION_NAME.ITEM_NAME AS Location, 
        INDIVIDUAL.TITLE AS Title, 
        INDIVIDUAL.FORENAME as Forename, 
        INDIVIDUAL.INITIALS as Initials,
        INDIVIDUAL.SURNAME as Surname, 
        SITE_STATUS.SHORT_NAME AS Status
FROM         
    NAME INNER JOIN
        INDIVIDUAL ON NAME.NAME_KEY = INDIVIDUAL.NAME_KEY INNER JOIN
        TENURE ON NAME.NAME_KEY = TENURE.OWNED_BY INNER JOIN
        LOCATION ON LOCATION.LOCATION_KEY = TENURE.LOCATION_KEY INNER JOIN
        TENURE_TYPE ON TENURE.TENURE_TYPE_KEY = TENURE_TYPE.TENURE_TYPE_KEY INNER JOIN
        LOCATION_NAME ON LOCATION.LOCATION_KEY = LOCATION_NAME.LOCATION_KEY INNER JOIN
        LOCATION_DESIGNATION ON LOCATION.LOCATION_KEY = LOCATION_DESIGNATION.LOCATION_KEY INNER JOIN
        SITE_STATUS ON LOCATION_DESIGNATION.SITE_STATUS_KEY = SITE_STATUS.SITE_STATUS_KEY

WHERE     
    (TENURE_TYPE.SHORT_NAME = 'Owner') 
    AND 
    (LOCATION_NAME.PREFERRED = 1) 
    AND 
    <Condition  operator="equal" field="Site_Status.Short_name" name="Designation "  type="Text" />
    --(SITE_STATUS.SHORT_NAME = 'pWildlife site')
    ORDER BY 
                  Location
</Where> 
</SQL>
<Columns>
    <Column name="LOCATION_KEY" tablename="Location key" visible="False" />
    <Column name="Location_key" position="1" caption="Location_key" width="120"/>
    <Column name="Status" position="2" caption="Status" width="100"/>
    <Column name="Location" position="3" caption="Location" width="200"/>
    <Column name="Preferred" position="4" caption="Preferred" visible="False" />
    <Column name="Tenure" position="5" caption="Tenure" keycolumn="Tenure" width="80"/>
    <Column name="Title" position="6" caption="Title" width="50"/>
    <Column name="Initials" position="7" caption="Initials" width="50"/>    
    <Column name="Forename" position="8" caption="Forename" width="100"/>
    <Column name="Surname" position="9" caption="Surname" width="100"/>
</Columns>
</CustomReport>

Note the new features I've incorporated into this (as compared with my first guide)
1. The <CustomReport line gives me the text for an opening dialog box
2. I've changed one of my "WHERE" statements so that it responds to the question asked in the opening dialog box, remming out the fixed statement "SITE_STATUS.SHORT_NAME = 'pWildlife site'" to help keep track of my changes.
3. The <Columns section works better now, the method for specifying column widths is correct.

Give the above one a try, my next effort will be to combine this with a similar statement for Organisations through the UNION statement so that I get a single list regardless of whether the land owner is an Individual or an Organisation. I can do it in Access but the Transact SQL methodology evades me for the moment.

2

Re: A simple guide to XML reports #2

Hi Darwyn,

A wee slightly unrelated question, how do you (successfully) link your Access db to the R6 database? I've tried & failed too many times too mention.

Cheers now, Rob.

3

Re: A simple guide to XML reports #2

Hi Rob

You should have a file called nbndata.mdb in the Database folder within a Recorder 6 installation.  This is a ready made Access database with each of the SQL Server tables linked into it, so you can use Access querying and reporting tools.

Cheers,

John van Breda
Biodiverse IT

4

Re: A simple guide to XML reports #2

So there's no need to make an additional linked database to this then?

Rob

5

Re: A simple guide to XML reports #2

Sort of.  The file created is in Access 97 format, so if you want to use it in Access 2000/2003 and create queries you will need to convert it into a different file. That can be done automatically when you open the file by Access.

John van Breda
Biodiverse IT

6 (edited by Darwyn Sumner (LERC) 14-08-2006 15:43:46)

Re: A simple guide to XML reports #2

I'm afraid I cannot be much help here, Rob. Mike Weideli left me with this "linked" database last time he visited us.

7

Re: A simple guide to XML reports #2

Rob,

I know this has probably been described already, but can you clarify exactly what problems you are having with the linked database? Does it exist, and if so what happens when you use it?

To clarify, although Recorder 6 stores data only in SQL Server, it creates an Access 97 database called nbndata.mdb in the Database folder as part of the installation process. The database contains ODBC linked tables which are just pointers to the SQL Server data, so that people with functionality and skills based on Access will not lost out by the move to SQL Server.

John van Breda
Biodiverse IT

8

Re: A simple guide to XML reports #2

Rob, do you have Access 2003, or an earlier version?

Charles Roper
Digital Development Manager | Field Studies Council
http://www.field-studies-council.org | https://twitter.com/charlesroper | https://twitter.com/fsc_digital

9

Re: A simple guide to XML reports #2

Hi there

Ok, I've got Access 2003. The Server version is Standard edition 2003 with SP 1.

When I had all our data on a standalone, I could make a linked mdb to NBNdata within the Database folder on the C drive, no problem. From there I was able to edit things like custodianships, run queries for date errors etc..usual stuff.

However since we've installed the server version, I'm unable to open any tables within NBNdata ( see screenshots form previous post), or open tables directly using the Enterprise manager. The other curious thing to note here is that R6 cannot be run on the server, only remotely; does it need a workstation install on ther server too?

From the various discussion we've had on this forum and also privately, the problem almost certainly seems to lie with permissions within our server and network, not Recorder itself.

Added to this, our ICT guys admit that they aren't fully up to speed with SQL either and are also concerned about all users being administrators.

Yet even with my own login being an admin, together with being the owner of all sub-folders within the server install, the above problems persist.

Hence my post on another thread about waiting for a more comprehensive guide to permissions which everyone concerned can understand.

Cheers now, Rob.

10

Re: A simple guide to XML reports #2

Rob,

Has your Windows User Account been added to the SQL Server as a SQL Server Login account? Once you've done that, you need to map the SQL Server Login to the database, then apply the roles you would like to apply to that database. I've found that when you haven't assigned the Login a role with suitable permission (like db_owner, or db_datareader and db_datawriter) then I get behaviour similar to yours.

It sounds complex because it is rather. I've been reading Administrator's Guide to SQL Server 2005 (ISBN:0-321-39797-5) which has helped my understanding of security a great deal.

Charles

Charles Roper
Digital Development Manager | Field Studies Council
http://www.field-studies-council.org | https://twitter.com/charlesroper | https://twitter.com/fsc_digital

11

Re: A simple guide to XML reports #2

Are you both using the Trusted Security option when you installed Recorder? If you use the default security option (not trusted) then all the security for SQL Server is handled for you. Recorder logs in to the database server using a 'public' login with readonly access only - (the NBNUser account). Then Recorder uses something called an application role in order to gain the required access levels within the system.

If you have ticked the "Use a trusted connection" option on the Login options screen on the network install, then you are effectively taking responsibility for ensuring that the required privileges are available for the users who intend to log in.

Also note that its quite valid for you to have a database where you aren't allowed to poke around directly via Enterprise manager.  You are able to do this on your own machine because local machine admin rights gives you full access to a local MSDE instance, but this is not the case with SQL Server, where Charles' previous comments about setting up an account apply. In fact the approach I prefer is to create a windows user group (e.g. called Recorder administrators), make sure you are in the group, and then add the group to the server as a login. Finally, add the group as a user of the NBNData database with db_datareader (and possibly db_datawriter) privileges.

John van Breda
Biodiverse IT

12

Re: A simple guide to XML reports #2

John, we use trusted security here. The scenario you outline is almost exactly how we are setup here. Have a look:

http://forums.nbn.org.uk/uploads.php?file=logins.png

Charles

Charles Roper
Digital Development Manager | Field Studies Council
http://www.field-studies-council.org | https://twitter.com/charlesroper | https://twitter.com/fsc_digital

13

Re: A simple guide to XML reports #2

John, When we installed , Mike W recommended the approach you suggest as well. However we had to use trusted security option because the 'sa' password is no longer accessible; -six months later this situation has not changed, either.

Have sent the above three posts doon-th'-stairs & will let you know how we get on.

Thanks again,  Rob

14

Re: A simple guide to XML reports #2

What do you mean by not accessible? Do you mean that your IT department won't let you have it? If that's true then surely they are accepting the fact that any installation & upgrade procedures will need to be undertaken by someone who does have the sa password?

Having access to the sa password should not make any difference to your decision to use trusted security or otherwise. The reason for this decision is that trusted security should be used when an IT department would like to use Windows Authentication to control access to their applications.

John van Breda
Biodiverse IT