Tuesday, March 20, 2012
calling custom assembly just wont work...
report and it just wont work.
my code is as follows:
--
Public Class Module1
Public Shared Function Hello() As Integer
Return 2
End Function
End Class
--
i want to use this function to calculate one of my
dataset parameters. i have used this expression:
=FundTrackHelper.Module1.Hello()
this is the error i get:
Error 102 [rsCompilerErrorInExpression] The Value expression for the query
parameter â'@.organ_pkeyâ' contains an error: [BC30389]
'FundTrackHelper.Module1' is not accessible in this context because it is
'Private'.
c:\srcsafe\vs2005\reports\fundtrackreports\fundtrackreports\TEST.rdl 0 0
i have copied the assembly into: C:\Program Files\Microsoft Visual Studio
8\Common7\IDE\PrivateAssemblies
i also did try to modify the rssrvpolicy.config file to grant the assembly
code
permissions beyond the default execute permissions but this had no effect
so i took the modification out. furthermore, i dont think a simple piece
of code like this needs any extra permissions anyway.
any ideas appreciated.
thanks.
t.Hi,
did you had a reference of the assemblie in the report property..
can you define the method as static function and access it?
"taz" wrote:
> i am trying to call a custom assembly from a
> report and it just wont work.
> my code is as follows:
> --
> Public Class Module1
> Public Shared Function Hello() As Integer
> Return 2
> End Function
> End Class
> --
> i want to use this function to calculate one of my
> dataset parameters. i have used this expression:
> =FundTrackHelper.Module1.Hello()
> this is the error i get:
> Error 102 [rsCompilerErrorInExpression] The Value expression for the query
> parameter â'@.organ_pkeyâ' contains an error: [BC30389]
> 'FundTrackHelper.Module1' is not accessible in this context because it is
> 'Private'.
> c:\srcsafe\vs2005\reports\fundtrackreports\fundtrackreports\TEST.rdl 0 0
> i have copied the assembly into: C:\Program Files\Microsoft Visual Studio
> 8\Common7\IDE\PrivateAssemblies
> i also did try to modify the rssrvpolicy.config file to grant the assembly
> code
> permissions beyond the default execute permissions but this had no effect
> so i took the modification out. furthermore, i dont think a simple piece
> of code like this needs any extra permissions anyway.
> any ideas appreciated.
> thanks.
> t.|||c
hi,
yes i did add to references but i am not sure what
to put in the report properties | class name and
instance name bits - any help appreciated.
here is my code (the project is called FundTrackHelper):
Namespace xyz
Public Class Module1
Public Shared Function Hello() As Integer
Return 2
End Function
End Class
End Namespace
"Bava Mani" wrote:
> Hi,
> did you had a reference of the assemblie in the report property..
> can you define the method as static function and access it?
>
>
> "taz" wrote:
> > i am trying to call a custom assembly from a
> > report and it just wont work.
> >
> > my code is as follows:
> >
> > --
> >
> > Public Class Module1
> > Public Shared Function Hello() As Integer
> >
> > Return 2
> >
> > End Function
> >
> > End Class
> >
> > --
> >
> > i want to use this function to calculate one of my
> > dataset parameters. i have used this expression:
> > =FundTrackHelper.Module1.Hello()
> >
> > this is the error i get:
> >
> > Error 102 [rsCompilerErrorInExpression] The Value expression for the query
> > parameter â'@.organ_pkeyâ' contains an error: [BC30389]
> > 'FundTrackHelper.Module1' is not accessible in this context because it is
> > 'Private'.
> > c:\srcsafe\vs2005\reports\fundtrackreports\fundtrackreports\TEST.rdl 0 0
> >
> > i have copied the assembly into: C:\Program Files\Microsoft Visual Studio
> > 8\Common7\IDE\PrivateAssemblies
> >
> > i also did try to modify the rssrvpolicy.config file to grant the assembly
> > code
> > permissions beyond the default execute permissions but this had no effect
> > so i took the modification out. furthermore, i dont think a simple piece
> > of code like this needs any extra permissions anyway.
> >
> > any ideas appreciated.
> >
> > thanks.
> >
> > t.|||I think the problem might be that as far as I know you can only call
static methods in classes. Try making it static and see if this works|||tried to make the method static and it tells me:
Methods cannot be declared 'Static'
doesnt the 'Shared' keyword do the same thing? if so, as
u can see i am already using that...
"Thomo" wrote:
> I think the problem might be that as far as I know you can only call
> static methods in classes. Try making it static and see if this works
>|||sorry Taz, I didn't notice this earlier, from what I understand the
Shared statment is the equivalent of static in C#
you said that you compiled the assembly into C:\Program Files\Microsoft
Visual Studio
8\Common7\IDE\PrivateAssemblies, the assemblies that I call from my
report however are simply placed under the GAC.
Can you check to see if your assembly is under the
c:\Windows\Assemblies\ folder
Also the error seems to be complaining about the access level of the
Class <i>'FundTrackHelper.Module1' is not accessible in this context
because it is 'Private'. </i>
Not sure why it would be doing this if the class and member are
declared as 'Public' as you say above, maybe write a small test app
that can reference the same class / method and make sure this works.|||this morning i basically deleted my custom assembly and
created a new one from scratch with a namespace and it
now works. thanks for your help. i am sure i'll have loads
of other questions as well !!!!!
"Thomo" wrote:
> sorry Taz, I didn't notice this earlier, from what I understand the
> Shared statment is the equivalent of static in C#
> you said that you compiled the assembly into C:\Program Files\Microsoft
> Visual Studio
> 8\Common7\IDE\PrivateAssemblies, the assemblies that I call from my
> report however are simply placed under the GAC.
> Can you check to see if your assembly is under the
> c:\Windows\Assemblies\ folder
> Also the error seems to be complaining about the access level of the
> Class <i>'FundTrackHelper.Module1' is not accessible in this context
> because it is 'Private'. </i>
> Not sure why it would be doing this if the class and member are
> declared as 'Public' as you say above, maybe write a small test app
> that can reference the same class / method and make sure this works.
>
Sunday, March 11, 2012
Calling a SP inside a cursor loop..
every loop iteration of the cursor. The pseudo code is as follows..
Create proc1 as
Begin
Variable declrations...
declare EffectiveDate_Cursor cursor for
select field1,fld2 from tab1,tab2 where tab1.effectivedate<Getdate()
--/////Assuming the above query would result in 3 records
Open EffectiveDate_Cursor
Fetch next From EffectiveDate_Cursor Into @.FLD1,@.FLD2
begin
/*Calling my second stored proc with fld1 as a In parameter
and Op1 and OP2 Out parameters*/
Exec sp_minCheck @.fld1, @.OP1 output,@.OP2 output
Do something based on Op1 and Op2.
end
While @.@.Fetch_Status = 0
Fetch next From EffectiveDate_Cursor Into @.FLD1,@.FLD2
/* Assume If loop count is 3.
and If the Fetch stmt is below the begin Stmt, the loop iterations are
4 else the loop iterations are 2*/
begin
/*Calling my second stored proc with fld1 as a In parameter and Op1
and OP2 Out parameters*/
Exec sp_minCheck @.fld1, @.OP1 output,@.OP2 output
Do something based on Op1 and Op2.
end
The problem I had been facing is that, the when a stored proc is called
within the loop, the proc is getting into infinite loops.
Any Help would be appreciated.
Satish(satishchandra999@.gmail.com) writes:
> I have SP, which has a cursor iterations. Need to call another SP for
> every loop iteration of the cursor. The pseudo code is as follows..
> Create proc1 as
> Begin
> Variable declrations...
>...
> While @.@.Fetch_Status = 0
> Fetch next From EffectiveDate_Cursor Into @.FLD1,@.FLD2
> /* Assume If loop count is 3.
> and If the Fetch stmt is below the begin Stmt, the loop iterations are
> 4 else the loop iterations are 2*/
> begin
> /*Calling my second stored proc with fld1 as a In parameter and Op1
> and OP2 Out parameters*/
> Exec sp_minCheck @.fld1, @.OP1 output,@.OP2 output
> Do something based on Op1 and Op2.
> end
>
> The problem I had been facing is that, the when a stored proc is called
> within the loop, the proc is getting into infinite loops.
May I guess: the inner process also uses cursors?
Anyway, the proper way to program a cursor loop is:
DECLARE cur INENSITIVE CURSOR FOR
SELECT ...
-- Error handling goes here
OPEN cur
WHILE 1 = 1
BEGIN
FETCH cur INTO @.x, @.y, ...
IF @.@.fetch_status <> 0
BREAK
-- Do stuff
END
DEALLOCATE cur
By using only one FETCH statements you avoid funny errors, when you change
the cursor and forgets to change the cursor at the end of the loop. And by
checl @.@.fetch_status directly after the FETCH, you know that @.@.fetch_status
relates to that FETCH.
... and in case no one ever told you before: avoid iterations as much as
you can, and try to always work set-based. Yes, I can understand that you
want to reuse code, and if the oomplexity is high enough it may be
warranted if the number of rows in the cursor is moderate. But the cost
in performance for iterative solutions can be *enourmous*. A database
engine is simply not designed for this type of processing.
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||>> I have SP, which has a cursor iterations. Need to call another SP for
every loop iteration of the cursor. <<
No. You need to learn to program in SQL. All you are doing is
mimicing a 1960's 3GL magnetic tape file system . In your pseudo
code, you even refer to fields instead of columns! You put the "sp_"
prefix on procedure names!
Don't you understand that SQL is a non-procedurdal language? You
should write only a few cursors in 20 years, not two in one
application.
Your whole approach to the problem is **fundamentally** wrong.
>> The problem I had been facing is that, the when a stored proc is called within the loop, the proc is getting into infinite loops. <<
It is very hard to de-bug code that you will not show us. But when
pseudo code is this awful, I bet that the real code is a total mess.
More cursors? Dynamic SQL? Badly written procedural code with poor
coupling and cohesion?
>> Any Help would be appreciated. <<
You have no idea what you are doing. What you will get on Newsgroups
is a quick kludge to get rid of you, but not any real help. You need
to stop programming and get some education; then get some training.
Sunday, February 19, 2012
Calculation gives different result on dev. machine and client machine
Does anyone have any idea what I can do to fix it?
//Code for Formula @.Duration
NumberVar nTimeLeft := {CallDuration};
NumberVar nHours := nTimeLeft \ 3600;
nTimeLeft := nTimeLeft - (nHours * 3600);
NumberVar nMinutes:= nTimeLeft \ 60;
nTimeLeft := nTimeLeft - (nMinutes * 60);
NumberVar nSeconds:= nTimeLeft;
//Sanity Check
IF (nHours * 3600) + (nMinutes * 60) + (nSeconds) = {CallDuration} THEN
Right ('0' + CStr(nHours), 2) + ':' + Right ('0' + CStr(nMinutes), 2) + ':' + Right ('0' + CStr(nSeconds), 2)
ELSE
CStr(nHours) + ':' + CStr(nMinutes) + ':' + CStr(nSeconds) + ' InvalidTime!';Found out why it's doing this, but need help fixing it...
On my machine, I have the default Number Format set up as ####. It seems that on the Client's machine (all of them), the default is #,###.00. As a result, my numbers would be displayed as follows:
1.00:2.00:3.00 for 1 hour, 2 minutes, and 3 seconds
when it should be displayed like this:
01:02:03
I have the code adding a leading zero, then taking the Right 2 characters to get it to display as 01 instead of 1. Since Crystal Formats the Numbers as 1.00, the Right function is capturing the 00 at the end and displaying like this:
00:00:00
Since the output is a string and not a number, there is no option (that I can see) for formatting the number before it's displayed.
Does anyone have any ideas on how I can get it to display properly?|||Problem solved...
I changed CStr(nHours) to ToText(nHours,0) and it worked. (The ',0' is the number of decimal places.)
Sunday, February 12, 2012
Calculating date/time from Unix time
A third party application writes phone call logs to an SQL Server 2000 database. The start and end times are unfortunately inserted as Unix time (seconds from 1-1-1970).
We want to make a monthly csv export of these records by selecting the detail records between certain dates/times but we are having problems calculating the correct date/timestamp as there seems to be no function in SQL server that can do this.
In stead of dumping the whole logfile (which is pretty big already) and making the selection in Oracle we would like to know if there is an easy way to do this with an SQL select statement on the database ?
Thank you in advance for your suggestions.
First of all you are on the wrong forum, check out the Transact-SQL (T-SQL) forum.
In the meantime, you may want to look at Books Online (BOL) and check out the CONVERT function and see if there's anything there that will help you. If not you can quite easily acheive this using some string manipulation functions of which there are plenty.
If you take the second of these options and you are using SQL2005 you may want to look at using a SQLCLR function which will carry out this operation quicker than a T-SQL function will.
-Jamie
Calculating average by hierarchy level
Hi all,
I have a problem which needs to be sorted out immediate in Analysis service Cube. My requirement is as follows
The following data explains the average value of each employee in corresponding level.
Level1 - > E1 – (25hrs /25days) =1 hrs/day
Level2 - >E2 – (125hrs /25days) = 5 hrs/day
Level3 >E4 – (150hrs /25days) = 6hrs/day
Level4 > E6 – (100hrs /25days) = 4hrs/day
Level4 > E7 – (75hrs/25days) = 3hrs/day
Level4 > E8 – (175hrs/25days) = 7hrs/day
Level3 >E5 – (75hrs/25days) = 3hrs/day
Level2 - >E3 – (100hrs /25days) = 4hrs/day
Eg:
I have productivity records of each day and each employee. I need to calculate avg of each last level employee productivity by monthly. Again Last level employee productivity avg must be added up with their immediate head. But, when I define a Measure Item as avg in the cube, it sums all the values of lost level employees & headand divides with number of records (normal avg).
My requirement is calculating each head avg by sum of each last level employee avgs / no of employees. If head having value, he too will be added. Again Head’s Avg will be added up immediate head.
The following calculation gives average value at each level.
Average of Level 3(E4) = > (4+3+7+6)/4 = 5 hrs/day< = (E6+E7+E8+E4)/4
Average of Level 2(E2) = > (5+3+5)/3= 4.333< =avg(Level3(E4))+avg(Level3(E5)))/2
Average of Level 1(E1) = > (4.333+4+1)/3 = 3.111
< = avg(Level3(E2))+avg(Level3(E3)))/2
Formula for average of level :
: (Sum of Children value + Head Value of Corresponding children) / (No.of Children +1)
I want to calculate average of each employee as well as average of each level in cube (SQL Server Analysis Services).
Thanks in advance
Thiru
I'm not 100% clear on what exactly you are wanting to calculate, so I started with the bolded string towards the end of your post:
(Sum of Children value + Head Value of Corresponding children) / (No.of Children +1)
Looking at this, I worked through some calculations on Adventure Works. Hopefully there is something in there that helps lead you to your answer.
Take a very close look at the formulas and the data returned by each. There is a very important concept illustrated in this example regarding Data Members. In a parent-child hierarchy, a member may have data of their own as well as data from its children. These are stored separately. Books Online has a good article on this, "Working with Attributes in Parent-Child Hierarchies ", which explains this in better detail than I can here.
Hope this leads you to a solution,
Bryan
Code Snippet
with member [Measures].[Num of Children Inc Self] as
COUNT(DESCENDANTS([Employee].[Employees].CurrentMember,,SELF_AND_AFTER))
member [Measures].[Self Quota] as
([Employee].[Employees].DataMember,[Measures].[Sales Amount Quota]),
format="Currency"
member [Measures].[Children Quota] as
SUM(
DESCENDANTS([Employee].[Employees].CurrentMember,,AFTER),
([Employee].[Employees].DataMember,[Measures].[Sales Amount Quota])
),
format="Currency"
member [Measures].[Self + Children Quota] as
[Measures].[Self Quota]+[Measures].[Children Quota]
member [Measures].[Avg Quota] as
[Measures].[Self + Children Quota]/[Measures].[Num of Children Inc Self]
select
{
[Measures].[Num Of Children Inc Self],
[Measures].[Sales Amount Quota],
[Measures].[Self Quota],
[Measures].[Children Quota],
[Measures].[Self + Children Quota],
[Measures].[Avg Quota]
} on 0,
DESCENDANTS([Employee].[Employees].[Brian S. Welcker],,SELF_AND_AFTER) on 1
from [Adventure Works]
;
Friday, February 10, 2012
Calculating % totals - what approach to take?
We have unique case numbers. I need to display how many cases took < 24 hours, how many cases took < 48 hours and how many took > 48 hours. As you can see, the count of cases < 24 will come in all the 3 i.e < 24, < 48 and > 48. I need to display % totals for the 3 categories.
What approach would be ideal? Any help is appreciated. I am using CR10 and SQL server as my database.First of all - the count of cases <24 will only come in 2 of the sections - <24 and <48 - it wouldn't come in at >48 b/c anything less than 24 won't ever be greater than 48.
I would make a summary field that does a running total(count) by a formula for each of the three types you want and another for the total count of all three. Then make formula fields for each one calculating the percent that way. I.E.
∑count / ∑totalcount = %
and put that in your report
Let me know if that didn't make sense