From: tuan3249 on
I wrote a simple function to call a stored procedure in the code tab of
the report property.
I did not write any custom assembly or dll.

Code is below:

public function Prepare(Office as integer, Dt as date)

Dim oConn As New system.data.SqlClient.SqlConnection("Connection String
Here")
Dim oCmd As New system.data.SqlClient.SqlCommand

Try
oConn.Open()

With oCmd
.Connection = oConn
.CommandText = "MyStoredProc"
.CommandType = System.Data.CommandType.StoredProcedure
.Parameters.Add("@OfficeID", Office)
.Parameters.Add("@EndDate", Dt)
.ExecuteNonQuery()
End With
Catch ex As Exception
throw ex
End Try
return Office

end Function

The only thing I added to the reference tab is the reference to
system.data. It has only one line: System.Data, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089

The report runs fine in the designer but when deploy, I get

An error has occurred during report processing.
The Value expression for the query parameter '@OfficeID' contains
an error: Request for the permission of type
'System.Data.SqlClient.SqlClientPermission, System.Data,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed.

Anyone has any idea?

From: Potter on
Looks like a Code Access Security issue. Did you put a code group for
System.Data in rssrvpolicy.config?

That's where I'd start looking.

By the way, why not use a dataset to query your stored proc?

Andy Potter

From: tuan3249 on
I did added a code group after reading a few posts but that didn't help
either. I may have the code group wrong tho.

<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="C:\Program Files\Microsoft
SQL Server\MSSQL.1\Reporting
Services\ReportManager\Bin\System.Data.dll"
/>

Is this correct?

From: tuan3249 on
Oh and the reason why I didn't put this in a dataset is because of a
timing issue. I needed to make sure this stored proc is called before
the dataset that the report uses gets its data. So basically this one
SP is dependent on another one.

Tuan

From: tuan3249 on
Just FYI to close up this topic.

I was able to solve my problem with creating a custom assembly and
adding a code group to the rssrvpolicy.config.

Otherwise my research lead to setting the
Report_Expressions_Default_Permission to FullTrust. That would give
all reports the ability to do almost anything which is bad since my
user can use the report builder functionality and essential have access
to every resource.

Hope this help if anybody else.