Showing posts with label custom. Show all posts
Showing posts with label custom. Show all posts

Thursday, March 8, 2012

database access with custom assembly

Hi,
I got a problem accessing the database from within the deployed report.
The report works perfectly well within my IDE (VS 2005 v8.0.5x) but when I
deploy it to the Report Server (SQL Server 2005, v 9.00.1399) no access to
the database can be established; the field containg the value shows '#ERROR'.
I adjusted the following things:
1) C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting
Services\ReportServer\rssrvpolicy.config
<CodeGroup class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="RSHelperCodeGroup"
Description="Code group for InfoFrame RS help functions">
<IMembershipCondition class="UrlMembershipCondition"
version="1"
Url="C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting
Services\ReportServer\bin\RSHelpFunction.dll" />
</CodeGroup>
This entry follows the following entry:
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="$CodeGen$/*" />
</CodeGroup>
2) function within dll:
public static string getData (string id)
{
private static string connstring = "Data Source=localhost;Network
Library=DBMSSOCN;Initial Catalog=TPP;User ID=userID;Password=password;";
SqlConnection connection = new SqlConnection(connstring);
string resultString = "";
try
{
connection.Open();
string select = "SELECT Text FROM tblXY where tblXY.ID = " + id;
SqlCommand comm = new SqlCommand(select, connection);
SqlDataReader reader = comm.ExecuteReader();
bool r = reader.Read();
//...
resultString = (string)reader.GetSqlString(0);
//some checks following
...
}
finally
{
if (connection != null)
connection.Close();
}
return resultString;
}
3) Assembly
I compiled the assembly (dll) with the following attribute:
[assembly: AllowPartiallyTrustedCallers]
4) Path for the dll
I copied the dll into the following folders:
C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting
Services\ReportServer\bin\RSHelpFunction.dll
and
C:\Program Files\Microsoft Visual Studio
8\Common7\IDE\PrivateAssemblies\RSHelpFunction.dll
It seems to me that this is a problem concerning the permission required for
executing the report on the server.
Any help is appreciated.
Thanks in advance.
HaraldHi,
the solution to my problem is, as I suspected, a security point.
I had to give special rights to the database access before opening the
connection to the database within the dll:
try {
SqlClientPermission perm = new
SqlClientPermission(System.Security.Permissions.PermissionState.Unrestricted);
perm.Assert();
connection.Open();
...
} ...
The rest of my coding and adjustments (i.e. CodeGroup,...) were ok.
Then everthing works fine even for the deployed report.
Regards
Harald
"Harald" wrote:
> Hi,
> I got a problem accessing the database from within the deployed report.
> The report works perfectly well within my IDE (VS 2005 v8.0.5x) but when I
> deploy it to the Report Server (SQL Server 2005, v 9.00.1399) no access to
> the database can be established; the field containg the value shows '#ERROR'.
> I adjusted the following things:
> 1) C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting
> Services\ReportServer\rssrvpolicy.config
> <CodeGroup class="UnionCodeGroup"
> version="1"
> PermissionSetName="FullTrust"
> Name="RSHelperCodeGroup"
> Description="Code group for InfoFrame RS help functions">
> <IMembershipCondition class="UrlMembershipCondition"
> version="1"
> Url="C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting
> Services\ReportServer\bin\RSHelpFunction.dll" />
> </CodeGroup>
> This entry follows the following entry:
> <CodeGroup
> class="UnionCodeGroup"
> version="1"
> PermissionSetName="FullTrust">
> <IMembershipCondition
> class="UrlMembershipCondition"
> version="1"
> Url="$CodeGen$/*" />
> </CodeGroup>
> 2) function within dll:
> public static string getData (string id)
> {
> private static string connstring = "Data Source=localhost;Network
> Library=DBMSSOCN;Initial Catalog=TPP;User ID=userID;Password=password;";
> SqlConnection connection = new SqlConnection(connstring);
> string resultString = "";
> try
> {
> connection.Open();
> string select = "SELECT Text FROM tblXY where tblXY.ID = " + id;
> SqlCommand comm = new SqlCommand(select, connection);
> SqlDataReader reader = comm.ExecuteReader();
> bool r = reader.Read();
> //...
> resultString = (string)reader.GetSqlString(0);
> //some checks following
> ...
> }
> finally
> {
> if (connection != null)
> connection.Close();
> }
> return resultString;
> }
> 3) Assembly
> I compiled the assembly (dll) with the following attribute:
> [assembly: AllowPartiallyTrustedCallers]
> 4) Path for the dll
> I copied the dll into the following folders:
> C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting
> Services\ReportServer\bin\RSHelpFunction.dll
> and
> C:\Program Files\Microsoft Visual Studio
> 8\Common7\IDE\PrivateAssemblies\RSHelpFunction.dll
> It seems to me that this is a problem concerning the permission required for
> executing the report on the server.
> Any help is appreciated.
> Thanks in advance.
> Harald

Database access in custom code

Hi, I'm trying to access a db from the custom code, but it doesn't seem
to be possible, because if i try to preview the report i get errors:
[BC30002] 'DAO.Recordset' type not defined, and some other similar
errors if i try to use SqlConnection ect.
Is it a strange behavior of my reporting services installation?
If not how can I access db from my custom code?I can do it fine so it must be something in your code.
A tip would be to try the customer code out by writing a simple windows
application that uses the code. If this works then the report server should
also work (unless you have security problems).
If you are writing the code in the Code properties of the report then be
sure to add the appropriate references in the references tab.
Craig
"Tur" <cenci.cristiano@.gmail.com> wrote in message
news:1141376485.288962.263920@.v46g2000cwv.googlegroups.com...
> Hi, I'm trying to access a db from the custom code, but it doesn't seem
> to be possible, because if i try to preview the report i get errors:
> [BC30002] 'DAO.Recordset' type not defined, and some other similar
> errors if i try to use SqlConnection ect.
> Is it a strange behavior of my reporting services installation?
> If not how can I access db from my custom code?
>|||Hi Craig, thank you so much for your answer!
I'm writing my custom code in the Code properties of the report, as you
say,
but I'm not sure how to add the appropriate references in reference
tab.
An example:
function MyFun(myStr as String) as String
Dim temp as DAO.Recordset
return "Nothing"
end function
raises an error: "d:\myPath\myRDL.rdl : [BC30002] 'DAO.Recordset' type
not defined."
I'm not sure of what is the problem...|||Hi Craig, thank you so much for your answer!
I'm writing my custom code in the Code properties of the report, as you
say,
but I'm not sure how to add the appropriate references in reference
tab.
An example:
function MyFun(myStr as String) as String
Dim temp as DAO.Recordset
return "Nothing"
end function
raises an error: "d:\myPath\myRDL.rdl : [BC30002] 'DAO.Recordset' type
not defined."
I'm not sure of what is the problem...|||Hi Craig, thank you so much for your answer!
I'm writing my custom code in the Code properties of the report, as you
say,
but I'm not sure how to add the appropriate references in reference
tab.
An example:
function MyFun(myStr as String) as String
Dim temp as DAO.Recordset
return "Nothing"
end function
raises an error: "d:\myPath\myRDL.rdl : [BC30002] 'DAO.Recordset' type
not defined."
I'm not sure of what is the problem...|||Firstly I urge you to try out your custom code from outside of Reporting
Services. This will give you 100 times better error messages plus you will
be able to debug your code which you can't do if you are writing the code in
the reports code.
After you have completed this and its all working fine then, and only then,
copy the code from the function in to the Code properties of the report.
Now the error you are currently getting is to do with a reference that the
report server is not aware of. To add this reference go to the
Report>Report Properties...>References and click on the "..." to add a new
reference.
Choose the DLL that contains the namespace for the DAO.Recordset and add it
to your report.
Craig
"Tur" <cenci.cristiano@.gmail.com> wrote in message
news:1141722816.893159.67500@.j33g2000cwa.googlegroups.com...
> Hi Craig, thank you so much for your answer!
> I'm writing my custom code in the Code properties of the report, as you
> say,
> but I'm not sure how to add the appropriate references in reference
> tab.
>
> An example:
> function MyFun(myStr as String) as String
> Dim temp as DAO.Recordset
> return "Nothing"
> end function
>
> raises an error: "d:\myPath\myRDL.rdl : [BC30002] 'DAO.Recordset' type
> not defined."
>
> I'm not sure of what is the problem...
>