Hello,
I have reports that have embedded code from a custom assembly.
In design, they work fine. When I deploy them and run them via the
Report Manager on production I get the following error in the cells
where I have this code running:
"Error in method xxxxxx - Request for the permission of type
System.Data.SqlClient.SqlClientPermission, System.Data,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
failed."
I have followed all previous articles, made changes to .config files,
etc., etc. Given the assembly full trust, etc. Still no luck.
Has ANYONE actually got this to work? Crystal reports was a pain, but
at least it worked!
Thanks for any help with this.
FabioIt sounds like you did not explicitly assert permissions to open a database
connection. Unless you assert (!) the permission explicitly, it will fail
with a security exception. Example for opening a connection to a SQL Server
in custom code / custom assemblies:
...
SqlClientPermission permission = new
SqlClientPermission(PermissionState.Unrestricted);
try
{
permission.Assert(); // Assert security permission !!!
SqlConnection conn = new SqlConnection("...");
conn.Open();
...
}
BTW: you don't need FullTrust for using the SqlClient in a custom assembly,
because the SqlClient is enabled for partial trust scenarios. Just check the
MSDN documentation on the SqlClientPermission class.
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
<fassmann@.gmail.com> wrote in message
news:1124303487.138374.35130@.g43g2000cwa.googlegroups.com...
> Hello,
> I have reports that have embedded code from a custom assembly.
> In design, they work fine. When I deploy them and run them via the
> Report Manager on production I get the following error in the cells
> where I have this code running:
> "Error in method xxxxxx - Request for the permission of type
> System.Data.SqlClient.SqlClientPermission, System.Data,
> Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
> failed."
> I have followed all previous articles, made changes to .config files,
> etc., etc. Given the assembly full trust, etc. Still no luck.
> Has ANYONE actually got this to work? Crystal reports was a pain, but
> at least it worked!
> Thanks for any help with this.
> Fabio
>|||Thanks Robert.
I am explicity asserting permissions. Here's the code I'm using. Am I
missing something?
Try
Dim permission As New
SqlClientPermission(Security.Permissions.PermissionState.Unrestricted)
permission.Assert()
'Use the MS data access app block to get the data reader
dr = _myDBAccess.ExecuteReader(_myConn,
CommandType.StoredProcedure, "Trader_GetTransByAssetID", New
SqlParameter("@.AssetID", nAssetID))
'Loop thru all transactions to build arraylist of
transaction objects
While (dr.Read())
objTrans = New Transaction(dr.GetInt32(COL_TRANSID),
dr.GetDateTime(COL_TRADEDATE), dr.GetSqlMoney(COL_DOLLARS).ToDouble,
sShareClass, 0.0, dr.GetSqlDecimal(COL_SHARES).ToDouble,
dr.GetSqlDecimal(COL_PRICE).ToDouble,
CType(dr.GetSqlInt16(COL_CALCSHAREBALANCE).ToString, Integer),
CType(dr.GetSqlInt16(COL_CALCCOSTBASIS).ToString, Integer))
arlTrans.Add(objTrans)
End While
Catch ex As Exception
_myErrorMessage += " Error in method
CDSC.BuildTransArray - " & ex.Message
Finally
'Clean Up
If Not (IsNothing(dr)) Then
dr.Close()
End If
End Try
Thanks for your help.|||OK, got it fixed.
You have to explicitly open the connection everywhere you use this. So,
we've got it added to every function/procedure within our assembly.
So not oly are we using the ExecuteReader, but we're opening the
connection each time as well.|||I have a similar problem, could you please give some example on this. when
you say
> So not oly are we using the ExecuteReader, but we're opening the
> connection each time as well.
do you mean you declare explicitly
Dim cn as sqlconnection = new sqlconnection(connectionstring)
after sqlclientpermission
From your example,
Try
Dim permission As New
SqlClientPermission(Security.Permissions.PermissionState.Unrestricted)
permission.Assert()
-----
' Dim _myConn as sqlconnection = new sqlconnection(connectionstring)
(adding this solved your issue?)
----
'Use the MS data access app block to get the data reader
dr = _myDBAccess.ExecuteReader(_myConn,
CommandType.StoredProcedure, "Trader_GetTransByAssetID", New
SqlParameter("@.AssetID", nAssetID
Appreciate your help on this.
--
kvs
"fassmann@.gmail.com" wrote:
> OK, got it fixed.
> You have to explicitly open the connection everywhere you use this. So,
> we've got it added to every function/procedure within our assembly.
> So not oly are we using the ExecuteReader, but we're opening the
> connection each time as well.
>|||Ok, here is what I tried but still getting error. Could you please tell me
what am I doing wrong or missing?
Dim permission As New
SqlClientPermission(Security.Permissions.PermissionState.Unrestricted)
permission.Assert()
'open connection explicitly
Dim cn As SqlConnection = New SqlConnection(cns)
cn.Open()
Try
Return SqlDataAccess.ExecuteDataSet(cn, sql, arp)
Finally
cn.Dispose()
End Try
--
Thanks.
kvs
"kvs" wrote:
> I have a similar problem, could you please give some example on this. when
> you say
> > So not oly are we using the ExecuteReader, but we're opening the
> > connection each time as well.
> do you mean you declare explicitly
> Dim cn as sqlconnection = new sqlconnection(connectionstring)
> after sqlclientpermission
> From your example,
> Try
> Dim permission As New
> SqlClientPermission(Security.Permissions.PermissionState.Unrestricted)
> permission.Assert()
> -----
> ' Dim _myConn as sqlconnection = new sqlconnection(connectionstring)
> (adding this solved your issue?)
> ----
> 'Use the MS data access app block to get the data reader
> dr = _myDBAccess.ExecuteReader(_myConn,
> CommandType.StoredProcedure, "Trader_GetTransByAssetID", New
> SqlParameter("@.AssetID", nAssetID
>
> Appreciate your help on this.
> --
> kvs
>
> "fassmann@.gmail.com" wrote:
> > OK, got it fixed.
> >
> > You have to explicitly open the connection everywhere you use this. So,
> > we've got it added to every function/procedure within our assembly.
> >
> > So not oly are we using the ExecuteReader, but we're opening the
> > connection each time as well.
> >
> >sql
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment