Showing posts with label method. Show all posts
Showing posts with label method. Show all posts

Friday, March 30, 2012

Passing Parameter

I've to create an instance reference to my custom assembly by constructor
method.
It works well with a Code into the report .rdl like this:
---
<Code>
Public Obj As MyClass
Protected Overrides Sub OnInit()
dim MyArg as String = 4
Obj = new MyClass(MyArg)
End Sub
</Code>
--
But i need to pass a real parameter so:
Obj = new MyClass(Parameters!MyPar.Value)
it don't work and break with the error
BC30469 "The reference to a member not shared needs a reference to an object"
(I translate this from the italian version.... sorry for my bad english!!!
How can i do'
Thanks a lot.Try using this reference.
Report.Parameters!MyPar.Value
that should work in the Code.section
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Riccardo" <Riccardo@.discussions.microsoft.com> wrote in message
news:A86E7571-051B-4185-A6EF-110FAFBD67DD@.microsoft.com...
> I've to create an instance reference to my custom assembly by constructor
> method.
> It works well with a Code into the report .rdl like this:
> ---
> <Code>
> Public Obj As MyClass
> Protected Overrides Sub OnInit()
> dim MyArg as String = 4
> Obj = new MyClass(MyArg)
> End Sub
> </Code>
> --
> But i need to pass a real parameter so:
> Obj = new MyClass(Parameters!MyPar.Value)
> it don't work and break with the error
> BC30469 "The reference to a member not shared needs a reference to an
> object"
> (I translate this from the italian version.... sorry for my bad
> english!!!
> How can i do'
> Thanks a lot.|||This not works, but the error is changed with a message box:
" Unable to load the assembly expressions. The expression refers to a
nonexistent parameter in the parameters's collection.".
This is not true, becouse the parameter exists.
Can you help me again?
"Wayne Snyder" wrote:
> Try using this reference.
> Report.Parameters!MyPar.Value
> that should work in the Code.section
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Riccardo" <Riccardo@.discussions.microsoft.com> wrote in message
> news:A86E7571-051B-4185-A6EF-110FAFBD67DD@.microsoft.com...
> > I've to create an instance reference to my custom assembly by constructor
> > method.
> > It works well with a Code into the report .rdl like this:
> > ---
> > <Code>
> > Public Obj As MyClass
> > Protected Overrides Sub OnInit()
> > dim MyArg as String = 4
> > Obj = new MyClass(MyArg)
> > End Sub
> > </Code>
> > --
> > But i need to pass a real parameter so:
> > Obj = new MyClass(Parameters!MyPar.Value)
> > it don't work and break with the error
> > BC30469 "The reference to a member not shared needs a reference to an
> > object"
> > (I translate this from the italian version.... sorry for my bad
> > english!!!
> > How can i do'
> > Thanks a lot.
>
>

Friday, March 23, 2012

Passing DateTime Parameter to Subreport (Error)

Hi guys,

I have managed to pass a string parameter form the main report to the subreport with no problems, but when i try and use the same method to pass a datetime type, i am issued with the following error messase:

"[rsErrorExecutingSubreport] An error occurred while executing the subreport ‘SubReportName’: The value provided for the report parameter 'MasterDate' is not valid for its type."

I cant see why it work for strings, but not for datetime. Any suggestions will be very much appreciated

Just to clarify, i am using the same dateTime type to define both main and sub report parameters|||Does anybody know why i am getting this error. Your help will be very much appreciated.|||Does anybody know why i am getting this error?

Wednesday, March 21, 2012

Passing an IN (a, b, c) list to a sproc as a string -- best method?

I want to do something like this in a stored proc:

--

Create Procedure dbo.GetPatients
@.PatientIdList varchar(200) -- comma separated list of PatientIDs
As

Select *
From Patients
Where PatientId In (@.PatientIdList)

--

I know the above won't work, but of course what I want is if
@.PatientIdList = '1,2,3' then I want Patient records with PatientIds
1, 2, and 3 returned.

It looks like the only way to do this is to build the SQL statement as
a string within the stored procedure ... which pretty much defeats the
usefulness of using precompiled sprocs as I understand it (better off
building a dynamic query against a View in that case).

Thoughts?

Joel Thornton ~ <groups@.joelpt.eml.cc>Joel,

Erland has a decent writing on this topic.

http://www.sommarskog.se/arrays-in-sql.html

--
-oj
http://www.rac4sql.net

"Joel Thornton" <joelpt@.eml.cc> wrote in message
news:c190a45a.0401072012.5c38ba06@.posting.google.c om...
> I want to do something like this in a stored proc:
> --
> Create Procedure dbo.GetPatients
> @.PatientIdList varchar(200) -- comma separated list of PatientIDs
> As
> Select *
> From Patients
> Where PatientId In (@.PatientIdList)
> --
> I know the above won't work, but of course what I want is if
> @.PatientIdList = '1,2,3' then I want Patient records with PatientIds
> 1, 2, and 3 returned.
> It looks like the only way to do this is to build the SQL statement as
> a string within the stored procedure ... which pretty much defeats the
> usefulness of using precompiled sprocs as I understand it (better off
> building a dynamic query against a View in that case).
>
> Thoughts?
> Joel Thornton ~ <groups@.joelpt.eml.ccsql

Wednesday, March 7, 2012

Pass RS SessionID via URL

Can anybody tell me if the following should work:
I am trying to start a report services session by calling the Render
method in code. This works fine - a session ID is generarted in the
SessionHeaderValue. Now, I would like to able to that same session
via URL. Here's the VB code snippit:
--
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
rs.SessionHeaderValue = sh
result = rs.Render(sender_button.CommandArgument, format, history_id,
_
dev_info, parameter_values, credentials, show_hide_toggle, encoding,
_
mime_type, report_history_parameters, warnings, stream_ids)
Dim temp As String
temp = "http://localhost/ReportServer?%2fDemo+Project%2fMyReport&rs:Command=Render&rs:SessionID="
& rs.SessionHeaderValue.SessionID
Response.Redirect(temp)
--
The redirect works fine, but the Report Server pops up a login screen.
If I have already started the session, and pass the session ID, should
the login still be required?
Any insight on this would be appreciated.
Thanks,
TerryIs rs.Url the same as the root of your temp string? I.e. it's localhost, not
the machine name?
--
Tudor Trufinescu
Dev Lead
Sql Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Terry Romance" <tedgromance@.yahoo.com> wrote in message
news:f284ebe.0407230821.3a7bb882@.posting.google.com...
> Can anybody tell me if the following should work:
> I am trying to start a report services session by calling the Render
> method in code. This works fine - a session ID is generarted in the
> SessionHeaderValue. Now, I would like to able to that same session
> via URL. Here's the VB code snippit:
> --
> rs.Credentials = System.Net.CredentialCache.DefaultCredentials
> rs.SessionHeaderValue = sh
> result = rs.Render(sender_button.CommandArgument, format, history_id,
> _
> dev_info, parameter_values, credentials, show_hide_toggle, encoding,
> _
> mime_type, report_history_parameters, warnings, stream_ids)
> Dim temp As String
> temp ="http://localhost/ReportServer?%2fDemo+Project%2fMyReport&rs:Command=Render&
rs:SessionID="
> & rs.SessionHeaderValue.SessionID
> Response.Redirect(temp)
> --
> The redirect works fine, but the Report Server pops up a login screen.
> If I have already started the session, and pass the session ID, should
> the login still be required?
> Any insight on this would be appreciated.
> Thanks,
> Terry|||Thanks for the reply, Tudor.
The Url of the reporting service is:
"http://localhost/ReportServer/ReportService.asmx" which matches the
root of the 'temp' string in the code.
Is there anything else I should check?
Thank you,
Terry
"Tudor Trufinescu \(MSFT\)" <tudortr@.ms.com> wrote in message news:<OyNbI52cEHA.2236@.TK2MSFTNGP10.phx.gbl>...
> Is rs.Url the same as the root of your temp string? I.e. it's localhost, not
> the machine name?
> --
> Tudor Trufinescu
> Dev Lead
> Sql Server Reporting Services
> This posting is provided "AS IS" with no warranties, and confers no rights.
>|||Tudor,
Ignore my last reply. The URL's were the same on my development box, but
different on our live server. After I made sure they were the same on the live
server, it worked.
Thanks for your help!
Regards,
Terry|||Tudor:
I spoke too soon. It works only if I run it from the local machine. If
I try to access it from a remote machine via IE, it asks for authorization.
Thanks,
Terry|||If your app and RS are on different machines, you may be hitting the 2
machine hop limitation that exists in NTLM. NTLM credentials do not flow on
more than one machine.
client => your app => RS server
If you are on Windows 2003, you can use Kerberos, and enable delegation
between your app machine and the RS server machine. You could also use basic
auth over SSL (do not use it over plain HTTP as credentials are passed in
un-encrypted on the wire) or forms/custom authentication - but that requires
you write more code and has numerous other security implications.
--
Tudor Trufinescu
Dev Lead
Sql Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Terry Romance" <tedgromance@.yahoo.com> wrote in message
news:f284ebe.0407270626.253a9ee4@.posting.google.com...
> Tudor:
> I spoke too soon. It works only if I run it from the local machine.
If
> I try to access it from a remote machine via IE, it asks for
authorization.
> Thanks,
> Terry

Saturday, February 25, 2012

pass a parameter to a SqlDataSource

I'm trying to pass my SqlDataSource a parameter that is defined in the code-behind file for the same page. I've tried the method below but it does not work. Is there a better way?


SubmitForm.ascx page:

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ connection string..... %>"
SelectCommand="sp_CourseMaterialShipment_GetCourses" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter DefaultValue="<% ProgramID %>" Name="programID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>

SubmitForm.ascx.vb page:

Private ProgramID as string = "25"

Public ReadOnly Property ProgramID() As String
Get
Return _ProgramID
End Get
End Property

Thanks

Jason


Hello my friend,

If this is what you want to do, take the DefaultValue attribute out of the aspx page and use the following in your code behind: -

sqlDataSource2.SelectParameters["programID"].DefaultValue = ProgramID;

Kind regards

Scotty

|||

worked. Thank you.

Jason

Monday, February 20, 2012

Pasing parameter-value to method in .dll

Hello,
I have a class in a .dll wich I instantiate in reporting services on
the References tab. The instance is called "Myinstance". I also have a
parameter called "parm1".
>From custom code I have:
Protected Overrides Sub OnInit()
MyInstance.company(Parameters!parm1.value)
End Sub
The method company is declared "public void company(string _company)".
My problem is, that I get the error:
"... The definition of the report "/MyReport" is invalid. There is an
error on line 1 of custom code: [BC30469] Reference to a non-shared
member requires an object reference."
If, in custom code, I hard-code the parameter to the method company
instead of trying to get it from a parameter, it works, so it look as
if I try to access the parameter-value before the parameter is
available or I'm accessing the parameter in a wrong way.
I need to pass the value of the parameter "parm1" to a method
"company(string _company)" before the report is build, as fields in
the report will call other functions in the .dll and what they return
depends on the value of "parm1" passed to the method "company".
So, any suggestion? What am I doing wrong?
Thanks in advance
/PeterHey Peter.
Add a variable to your assembly call such as:
Protected Overrides Sub OnInit(parm1 as string)
MyInstance.company(Parameters!parm1.value)
End Sub
Then call you custom code like:
=code.oninit(parameters!parm1.value)
Michael
"Peter" wrote:
> Hello,
> I have a class in a .dll wich I instantiate in reporting services on
> the References tab. The instance is called "Myinstance". I also have a
> parameter called "parm1".
> >From custom code I have:
> Protected Overrides Sub OnInit()
> MyInstance.company(Parameters!parm1.value)
> End Sub
> The method company is declared "public void company(string _company)".
> My problem is, that I get the error:
> "... The definition of the report "/MyReport" is invalid. There is an
> error on line 1 of custom code: [BC30469] Reference to a non-shared
> member requires an object reference."
> If, in custom code, I hard-code the parameter to the method company
> instead of trying to get it from a parameter, it works, so it look as
> if I try to access the parameter-value before the parameter is
> available or I'm accessing the parameter in a wrong way.
> I need to pass the value of the parameter "parm1" to a method
> "company(string _company)" before the report is build, as fields in
> the report will call other functions in the .dll and what they return
> depends on the value of "parm1" passed to the method "company".
> So, any suggestion? What am I doing wrong?
> Thanks in advance
> /Peter
>|||Oops one small change
"Michael C" wrote:
Protected Overrides Sub OnInit(parm1 as string)
MyInstance.company(parm1)
End Sub
Michael
> Hey Peter.
> Add a variable to your assembly call such as:
> Protected Overrides Sub OnInit(parm1 as string)
> MyInstance.company(Parameters!parm1.value)
> End Sub
> Then call you custom code like:
> =code.oninit(parameters!parm1.value)
> Michael
> "Peter" wrote:
> > Hello,
> >
> > I have a class in a .dll wich I instantiate in reporting services on
> > the References tab. The instance is called "Myinstance". I also have a
> > parameter called "parm1".
> >
> > >From custom code I have:
> >
> > Protected Overrides Sub OnInit()
> > MyInstance.company(Parameters!parm1.value)
> > End Sub
> >
> > The method company is declared "public void company(string _company)".
> >
> > My problem is, that I get the error:
> >
> > "... The definition of the report "/MyReport" is invalid. There is an
> > error on line 1 of custom code: [BC30469] Reference to a non-shared
> > member requires an object reference."
> >
> > If, in custom code, I hard-code the parameter to the method company
> > instead of trying to get it from a parameter, it works, so it look as
> > if I try to access the parameter-value before the parameter is
> > available or I'm accessing the parameter in a wrong way.
> >
> > I need to pass the value of the parameter "parm1" to a method
> > "company(string _company)" before the report is build, as fields in
> > the report will call other functions in the .dll and what they return
> > depends on the value of "parm1" passed to the method "company".
> >
> > So, any suggestion? What am I doing wrong?
> >
> > Thanks in advance
> > /Peter
> >
> >|||On 19 Jul., 18:20, Michael C <Micha...@.discussions.microsoft.com>
wrote:
> Oops one small change
> "Michael C" wrote:
> Protected Overrides Sub OnInit(parm1 as string)
> MyInstance.company(parm1)
> End Sub
> Michael
>
> > Hey Peter.
> > Add a variable to your assembly call such as:
> > Protected Overrides Sub OnInit(parm1 as string)
> > MyInstance.company(Parameters!parm1.value)
> > End Sub
> > Then call you custom code like:
> > =code.oninit(parameters!parm1.value)
> > Michael
> > "Peter" wrote:
> > > Hello,
> > > I have a class in a .dll wich I instantiate in reporting services on
> > > the References tab. The instance is called "Myinstance". I also have a
> > > parameter called "parm1".
> > > >From custom code I have:
> > > Protected Overrides Sub OnInit()
> > > MyInstance.company(Parameters!parm1.value)
> > > End Sub
> > > The method company is declared "public void company(string _company)".
> > > My problem is, that I get the error:
> > > "... The definition of the report "/MyReport" is invalid. There is an
> > > error on line 1 of custom code: [BC30469] Reference to a non-shared
> > > member requires an object reference."
> > > If, in custom code, I hard-code the parameter to the method company
> > > instead of trying to get it from a parameter, it works, so it look as
> > > if I try to access the parameter-value before the parameter is
> > > available or I'm accessing the parameter in a wrong way.
> > > I need to pass the value of the parameter "parm1" to a method
> > > "company(string _company)" before the report is build, as fields in
> > > the report will call other functions in the .dll and what they return
> > > depends on the value of "parm1" passed to the method "company".
> > > So, any suggestion? What am I doing wrong?
> > > Thanks in advance
> > > /Peter
Hello Michael,
Thanks for your reply.
There are two issues:
1) I forgot to mention, that pam1 gets its values from a query, so I
cannot call my custom code as "=code.oninit(parameters!parm1.value)"
2) When I tried the custom code in your message, I got this error:
"... There is an error on line 0 of custom code: [BC30284] sub
'OnInit' cannot be declared 'Overrides' because it does not override a
sub in a base class."
What should I do from here ?
Thanks
/Peter|||hey Peter,
Well ...
1) The "Parmameter!Parm1.Value" could be "Fields!MyField.value", or if it is
not generated from the dataset that drives the report (i.e. a secondary
query) then you can use First(Fields!MyField.Value,"MyParmQuery")
2) I haven't worked with Overrides, are you required to have 'Protected
Overrides' in the call, or can you simply state Protected Sub
OnInit(strParm1) or even Public Sub OnInit?
Michael
"Peter" wrote:
> On 19 Jul., 18:20, Michael C <Micha...@.discussions.microsoft.com>
> wrote:
> > Oops one small change
> >
> > "Michael C" wrote:
> >
> > Protected Overrides Sub OnInit(parm1 as string)
> > MyInstance.company(parm1)
> > End Sub
> >
> > Michael
> >
> >
> >
> > > Hey Peter.
> >
> > > Add a variable to your assembly call such as:
> >
> > > Protected Overrides Sub OnInit(parm1 as string)
> > > MyInstance.company(Parameters!parm1.value)
> > > End Sub
> >
> > > Then call you custom code like:
> >
> > > =code.oninit(parameters!parm1.value)
> >
> > > Michael
> >
> > > "Peter" wrote:
> >
> > > > Hello,
> >
> > > > I have a class in a .dll wich I instantiate in reporting services on
> > > > the References tab. The instance is called "Myinstance". I also have a
> > > > parameter called "parm1".
> >
> > > > >From custom code I have:
> >
> > > > Protected Overrides Sub OnInit()
> > > > MyInstance.company(Parameters!parm1.value)
> > > > End Sub
> >
> > > > The method company is declared "public void company(string _company)".
> >
> > > > My problem is, that I get the error:
> >
> > > > "... The definition of the report "/MyReport" is invalid. There is an
> > > > error on line 1 of custom code: [BC30469] Reference to a non-shared
> > > > member requires an object reference."
> >
> > > > If, in custom code, I hard-code the parameter to the method company
> > > > instead of trying to get it from a parameter, it works, so it look as
> > > > if I try to access the parameter-value before the parameter is
> > > > available or I'm accessing the parameter in a wrong way.
> >
> > > > I need to pass the value of the parameter "parm1" to a method
> > > > "company(string _company)" before the report is build, as fields in
> > > > the report will call other functions in the .dll and what they return
> > > > depends on the value of "parm1" passed to the method "company".
> >
> > > > So, any suggestion? What am I doing wrong?
> >
> > > > Thanks in advance
> > > > /Peter
> Hello Michael,
> Thanks for your reply.
> There are two issues:
> 1) I forgot to mention, that pam1 gets its values from a query, so I
> cannot call my custom code as "=code.oninit(parameters!parm1.value)"
> 2) When I tried the custom code in your message, I got this error:
> "... There is an error on line 0 of custom code: [BC30284] sub
> 'OnInit' cannot be declared 'Overrides' because it does not override a
> sub in a base class."
> What should I do from here ?
> Thanks
> /Peter
>|||On 20 Jul., 18:56, Michael C <Micha...@.discussions.microsoft.com>
wrote:
> hey Peter,
> Well ...
> 1) The "Parmameter!Parm1.Value" could be "Fields!MyField.value", or if it is
> not generated from the dataset that drives the report (i.e. a secondary
> query) then you can use First(Fields!MyField.Value,"MyParmQuery")
> 2) I haven't worked with Overrides, are you required to have 'Protected
> Overrides' in the call, or can you simply state Protected Sub
> OnInit(strParm1) or even Public Sub OnInit?
> Michael
Thanks again Michael,
I have to declared it 'Protected' otherwise it will complain that I
use a different access level.
If I declared it Protected Overrides Sub OnInit(DataArea As String),
that is, with one parameter, I get the error:
sub 'OnInit' cannot be declared 'Overrides' because it does not
override a sub in a base class.
If I declare it without any parameters as Protected Overrides Sub
OnInit(), I get the error
Reference to a non-shared member requires an object reference
If I declare it without 'Overrides' (with and without a parameter) I
get the error
Reference to a non-shared member requires an object reference
So I'm stuck again. I need to use a function that is executed before
the report is generated. I need it to call a method i my .dll with an
argument which is based on a selection from a parameter which in turn
is based on a dataset.
What should I try from here?
Thanks
/Peter