Showing posts with label trouble. Show all posts
Showing posts with label trouble. Show all posts

Friday, March 30, 2012

Ive never been good with relationships

I'm having some trouble working out how to query some data. Rather than explain up front, here's some examples of what I want to achieve:

*******************************************************

I've got a structure which looks vaguely like this:

[ANCESTORS]

Grandparent
Parent
Child

If limit by grandparents, then I only get the lineage for that particular grandparent. I.e.:


SELECT *
FROM [ANCESTORS]
(some sortof joins here )
Where Grandparent.Name ='Cybill'

This would return all of the children of 'Cybill' and their children. Now, if I use the following query:


SELECT *
FROM [ANCESTORS]
(some sortof joins here )
Where Child.Name ='Jean'

This would return Jean's parents + the parents of Jean's parents (Jean's grandparents).

Likewise, if I enter:


SELECT *
FROM [ANCESTORS]
(some sortof joins here )
Where Parent.Name ='Ron'

Then I would get Ron's parents and also his children.

*******************************************************

So, as you can see, at first it appears that I'm after a LEFT JOIN - meaning that the grandparents don't need to have child records to be returned, but, then it turns out that I need INNER JOINS - to limit grandparents when I choose children.

Can anybody see my dilemma here?

Mark-up ASP.net posts here
MarkItUp.com... no. I don't. I've done something like this before with someone, and we didn't go about that method. :(

What's the problem with doing inner joins?|||Because, with Inner JOINs I am relying upon the existance of children to be able to return the grandparents.|||I actually have one table "Ancestors" and also a separate linking table which contains the relationships:

[Ancestors] ( id int, Name varchar )
[Relationships] ( id, fkid )

What I need to be able to do is to write a single query which can span "up to 7" lines of descendency, that is:

Great-Great-Great-Grandparent
Great-Great-Grandparent
Great-Great-Grandparent
Great-Grandparent
Grandparent
Parent
Child

I just have absolutely no idea how to write a single sql query which could filter on one or more levels but ensure referential integrity down the line. In other words, I can specify a child which would trace up the tree in a single line, or, specify a Great-Great-Great-Grandparent which would span out from a single point and would show all the way down to leaf nodes regardless of which level they finished at.|||Can we use a UDF? :-)|||Yes, I'm using SqlServer 2K.

I have finally tuned the stored procedure "program" enough to get my - previously 14 hour (give or take 100 milliseconds) - query down to sub-20 seconds. This is good enough to ship to the client so, I'm going to go with what I have for now.|||20 seconds? I'm still not believing that to be good enough. :) but if it's good enough for the client, it's good enough I guess.

If you're using any temp tables or what not, try indexing them before you apply data to them. I trimmed a procedure that executed in 12 seconds to 2.|||KraGiE, I agree, 20 seconds is a long time to wait, but, it's working so that's a much better position than I had 2 days ago.

I do have # temp tables, about 12 of them actually (more on that later), and my final optimization was to add indexes and optimization hints in the appropriate places, this reduced a 2 minute 20 second query to sub 30 seconds.

As for the 12 temp tables, this, to me was a fair indicator that the schema of the database was wrong to begin with so now, I 'm actually pushing to have the db schema altered too. I'm hoping that this will give me enough of a foothold to be able to achieve the necessary remaining improvements|||Personally, I'm a big fan of int based look up tables. :) Well, in cases like this, I'm fond of them because you can branch them out as far as you want without having just 'add a new field'.

I also think loops are my best friend when used properly.

What I meant by the indexes (if this is what you're doing already, then I'm a redundant moron) is ...


SET NOCOUNT ON

CREATE TABLE #TempTable
(
tableID int IDENTITY,
TableField varchar(50)
SomeOtherVar int
)
GO

CREATE INDEX idx_Temp
ON #TempTable ( tableID )
GO

INSERT INTO #TempTable
SELECT
TableID,
TableField,
SomeOtherVar
FROM
RealTable
-- WHERE Your Criteria

GO

-- Do Other Calculations

TRUNCATE TABLE #TempTable
DROP INDEX idx_Temp
DROP TABLE #TempTable

GO
-- Yes Terri, I space my sql in procedures and QA this way normally, and I'm just lazy when I post here. :)

|||Yeh, that's pretty much what I'm doing already re: the indexes ( although who am I to call you a redundant moron :P ) except that I create the index only after population and, therefore also set the fill factor to 100% - but, for the purposes of an illustration, yes, that's pretty much what I do.|||awesome. In some cases, I'll put the index in before I start populating if the data's going to be enormous. It sets a bit faster from my experience.

ITW says workload does not contain events or queries to use

Hi,
I'm having trouble getting the Index Tuning Wizard to analyze my workload.
I'm using SQL Server 2000. I've run the ITW against several different trace
files, and keep getting an error that says, "The workload does not contain
any events or queries that can be tuned against current database. Check to
see that the trace contains valid events or that the SQL script contains
valid queries and you are tuning against the right database."
In one case, as a test I ran the ITW against a trace file that I had run it
on about a month ago and gotten results from. Even with that file I still go
t
this error. In other cases when I try to run ITW on an older trace file, it
crashes. I've tried running ITW from another user's computer, with the same
result, so it doesn't seem to be my computer that's at fault.
I'm using the SqlProfilerTuning trace template. I've checked my trace
template against the same template on another computer to see if I had
changed something and broken it, but the only difference was that mine was
recording one additional data column, ApplicationName.
The events I'm recording are RPC:Completed and SQL:BatchCompleted.
There have definitely been data updates to at least some of the tables I'm
asking it to analyze. In some cases there have not been many updates (a doze
n
to a few dozen)--ITW documentation indicates that the ITW may fail if there
have not been enough changes to analyze, but it doesn't give any indication
as to what is enough.
Any suggestions what might be the problem, or how I could find out what the
problem is?
EachusDid you take a look at BOL Index: "Troubleshooting the Index Tuning Wizard"
?
HTH,
Vinod Kumar
MCSE, DBA, MCAD, MCSD
http://www.extremeexperts.com
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp
"Eachus" <Eachus@.discussions.microsoft.com> wrote in message
news:42FB19DB-3631-4F02-A3BB-71A2B7EDFABD@.microsoft.com...
> Hi,
> I'm having trouble getting the Index Tuning Wizard to analyze my workload.
> I'm using SQL Server 2000. I've run the ITW against several different
trace
> files, and keep getting an error that says, "The workload does not contain
> any events or queries that can be tuned against current database. Check to
> see that the trace contains valid events or that the SQL script contains
> valid queries and you are tuning against the right database."
> In one case, as a test I ran the ITW against a trace file that I had run
it
> on about a month ago and gotten results from. Even with that file I still
got
> this error. In other cases when I try to run ITW on an older trace file,
it
> crashes. I've tried running ITW from another user's computer, with the
same
> result, so it doesn't seem to be my computer that's at fault.
> I'm using the SqlProfilerTuning trace template. I've checked my trace
> template against the same template on another computer to see if I had
> changed something and broken it, but the only difference was that mine was
> recording one additional data column, ApplicationName.
> The events I'm recording are RPC:Completed and SQL:BatchCompleted.
> There have definitely been data updates to at least some of the tables I'm
> asking it to analyze. In some cases there have not been many updates (a
dozen
> to a few dozen)--ITW documentation indicates that the ITW may fail if
there
> have not been enough changes to analyze, but it doesn't give any
indication
> as to what is enough.
> Any suggestions what might be the problem, or how I could find out what
the
> problem is?
> Eachus|||Thanks for the suggestion. Yes, I have read that page. It doesn't address
either of the messages that I'm receiving.
The messages I receive most often is:
"The workload does not contain any events or queries that can be tuned
against current database. Check to see that the trace contains valid events
or that the SQL script contains valid queries and you are tuning against the
right database."
Sometimes I get this message:
"There are no events in the workload. Either the trace file contained no SQL
batch or RPC events or the SQL script contained no SQL queries."
According to all the documentation I can find, the RPC:Completed and
SQL:BatchCompleted events that the trace is capturing are what ITW needs, so
that message doesn't make any sense.
Laura
"Vinod Kumar" wrote:

> Did you take a look at BOL Index: "Troubleshooting the Index Tuning Wizard
"
> ?
> --
> HTH,
> Vinod Kumar
> MCSE, DBA, MCAD, MCSD
> http://www.extremeexperts.com
> Books Online for SQL Server SP3 at
> http://www.microsoft.com/sql/techin.../2000/books.asp
> "Eachus" <Eachus@.discussions.microsoft.com> wrote in message
> news:42FB19DB-3631-4F02-A3BB-71A2B7EDFABD@.microsoft.com...
> trace
> it
> got
> it
> same
> dozen
> there
> indication
> the
>
>

Wednesday, March 21, 2012

Issues with privileges

I am having trouble with providing the minimum security to a user. After issuing the following:

GRANT EXECUTE ON SCHEMA :: DBO TO skillsnetuser;

I test the permissions with

exec as login = 'skillsnetuser'

exec prcElmtList 1, 1, 102268

revert;

and receive this message

Msg 229, Level 14, State 5, Line 2

SELECT permission denied on object 'Org', database 'SNAccess_Dev', schema 'dbo'.

The principal that owns the dbo schema is dbo and is the principle for all procedures and tables in that schema.

What can I do to shed some light on what is causing this access problem?

Are the objects 'Org' and the procedure prcElmList defined in the same database ?|||Yes, Org is a table that prcElmList accesses|||

My first guess is that ownership chaining is broken for some reason. Can you please include the portion of the SP body that access the table? We can take a look to it and try to determine why ownership chaining is broken in this case.

I would also like to suggest migrating to one of the other mechanisms we have available on SQL Server 2005 that allow controlled access to resources via a module (i.e. SP) execution:

* EXECUTE AS – For more information you can visit Context Switching in BOL (http://msdn2.microsoft.com/en-us/library/ms188268.aspx)

* module signing: Module signing in BOL (http://msdn2.microsoft.com/en-us/library/ms345102.aspx)

Thanks a lot,

-Raul Garcia

SDE/T

SQL Server Engine

|||

IF NOT EXISTS (SELECT

o.OrgID

FROM

Org o

WHERE

o.OrgID = @.piOrgID

AND o.Active = 1

AND o.BeginDate < GetDate()

AND (o.EndDate > GetDate() OR o.EndDate IS NULL) )

BEGIN

RAISERROR ('The passed OrgID is invalid or inactive.' ,17 ,1)

RETURN -2 -- OrgID not valid or active

END -- IF NOT EXISTS

|||

I tried a similar scenario, and it seems to work for me, and as your sample code doen’t involve any dynamic SQL I am not sure what I may be missing. Can you give us some more information?

I would like to ask you to run the following query:

SELECT name, principal_id, schema_id

FROM sys.objects WHERE

name LIKE 'prcElmtList'

OR name LIKE 'Org'

I would also like to ask you if you are using a database in backwards compatibility mode (and if so, what is the compatibility level you are using) and if you are using any options for the stored procedure declaration (such as NOT FOR REPLICATION, EXECUTE AS, etc.), and if there are more objects involved in the chain other than the SP and the table.

Thanks a lot,

-Raul Garcia

SDE/T

SQL Server Engine

|||

SELECT name, principal_id, schema_id

FROM sys.objects WHERE

name LIKE 'prcElmtList'

OR name LIKE 'Org'

--Results

name principal_id schema_id

Org NULL 1

prcElmtList NULL 1

--For the procedure generation script

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

WITH RECOMPILE

--General Properties of the procedure showned by the GUI

Execute as caller

Schema dbo

System object False

ANSI NULLS True

Encrypted False

For replication False

Quoted identifier True

Recompile True

--Database Options showned by the GUI

Compatibility Level SQL Server 2005 (90)

All Miscellaneous Settings are False except Parameterization which is Simple

|||

At this junction I have added with execute as owner to the procedures,

this provides the functionality I was expecting to be present....

|||

Sorry for the late response, I have been trying to repro why ownership chaining didn’t worked for this particular scenario, I tried creating a small repro similar to the one you described, but so far I have no luck (my repro test is able to access the table as expected).

If you consider it is a bug in the product, I would recommend following the instructions described on the “Tips on using SQL Server Security forums” page to report it (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=286374&SiteID=1). We will probably need more details than the ones we have right now to continue the investigation.

I am glad you were able to find a solution for the problem. Please, let us know if you have any further questions or feedback; we will greatly appreciate your feedback on the EXECUTE AS feature.

Thanks a lot,

-Raul Garcia

SDE/T

SQL Server Engine

Monday, March 12, 2012

issue with RS 2000, WSS and asp.net 2.0

I am having trouble upgrading a machine. It has Reporting Services(RS) 2000 SP2 and Windows Sharepoint Services (WSS) SP2 running side by side. They are working just fine and have been for quite some time. The problem is I would like to have .net 2.0 installed as well. When I installed it, some things broke.

Specifically, now when I go to http://machinename/reports or http://machinename/reportserver, I get an error page that says "Server Error in '/Reports' Application" and points to the web.config file. The Parser Error Message says "Unrecognized attribute 'processRequestInApplicationTrust' ".

Does anyone know how to get all three running on the same machine? Is this even allowed?

Any help that you can provide would be appreciated. I am stuck.

Dennis

The problem is that Web.Config files are inherited. So your "/reports" which is .net 1.1 is inheriting a .net 2.0 web.config and it doesn't recognize some tags. Only solution I know of is to rearrange the folder hierarchy to not have 1.1 apps under 2.0 apps. I would love a 2.0 version of Report Server... Anyone know if it exists?

-Jesse