Thursday, March 29, 2012
Help with Custom Security Extension and Application Pool Identity
We have implemented a custom security extension that we call from
within an application. We pass in a userid and password into the
LogonUser method, which is then checked against our database.
However, we have a Master database, and then a few other small
databases for different clients, so the extension uses another
supplied value to go to the master database, and lookup which database
it needs to verify the user in.
So, in the RSReportServer.config file, we store the connection string
to the Master DB.
This is used to connect to the Master DB, and then lookup the
connection string for the secondary DB.
The connection string for the secondary DB uses Integrated
Authentication (as our application requires this).
When the Application Pool (in IIS) that ReportServer runs under, is
set to the NetworkUser, we get an error returned from the WebService
(called from within our application), which says that the Network
Service was not authorized to access the secondary DB. Understandable
:)
So, we changed the Application Pool, so that it uses a Domain account
as it's Identity. Now we receive the following error back (and in all
the log files I can find)..
System.Web.Services.Protocols.SoapException: An internal error
occurred on the report server. See the error log for more details.
--> Microsoft.ReportingServices.Diagnostics.Utilities.InternalCatalogException:
An internal error occurred on the report server. See the error log for
more details. --> System.IO.FileNotFoundException: The system cannot
find the file specified. at
System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32
errorCode, IntPtr errorInfo) at
RSManagedCrypto.RSCrypto.ExportPublicKey() at
Microsoft.ReportingServices.Library.ConnectionManager.GetEncryptionKey()
at Microsoft.ReportingServices.Library.ConnectionManager.ConnectStorage()
at Microsoft.ReportingServices.Library.ConnectionManager.VerifyConnection()
at Microsoft.ReportingServices.Library.ConnectionManager.get_Connection()
at Microsoft.ReportingServices.Library.Storage.get_Connection() at
Microsoft.ReportingServices.Library.Storage.NewStandardSqlCommand(String
storedProcedureName) at
Microsoft.ReportingServices.Library.DBInterface.GetOneConfigurationInfo(String
key) at Microsoft.ReportingServices.Library.CachedSystemProperties.GetSystemProperty(String
name) at Microsoft.ReportingServices.Library.CachedSystemProperties.Get(String
name) at Microsoft.ReportingServices.Library.CachedSystemProperties.GetParameter(String
name) at Microsoft.ReportingServices.Library.RSService.get_MyReportsEnabled()
at Microsoft.ReportingServices.Library.RSService.PathToInternal(String
source) at Microsoft.ReportingServices.Diagnostics.CatalogItemContext.SetPath(String
path, Boolean validate, Boolean convert, Boolean translate) at
Microsoft.ReportingServices.Diagnostics.CatalogItemContext.SetPath(String
path) at Microsoft.ReportingServices.Diagnostics.CatalogItemContext..ctor(IPathTranslator
pathTranslator, String userSuppliedPath, String parameterName) at
Microsoft.ReportingServices.Library.RSService.FindItems(String folder,
String operation, SearchCondition[] properties) -- End of inner
exception stack trace -- at
Microsoft.ReportingServices.Library.RSService.FindItems(String folder,
String operation, SearchCondition[] properties) at
Microsoft.ReportingServices.WebServer.ReportingService.FindItems(String
Folder, BooleanOperatorEnum BooleanOperator, SearchCondition[]
Conditions, CatalogItem[]& Items) -- End of inner exception stack
trace -- at Microsoft.ReportingServices.WebServer.ReportingService.FindItems(String
Folder, BooleanOperatorEnum BooleanOperator, SearchCondition[]
Conditions, CatalogItem[]& Items)
The Application Pool User is a member of the IIS_WPG group, and has
been granted write access to the Windows\Temp folder, and the MSSQL
folder where RS is installed (and sub folders).
I also tried adding it to the local machine admin group, and it made
no difference.
That user also has DBO access to all the DBs on our database server.
Can anyone help please?
Thanks
RichardWill you send the report server web service log file?
Also, can you verify that the new identity has a user profile on the machine
(the user should have an entry under c:\Documents and Settings)?
--
This posting is provided "AS IS" with no warranties, and confers no rights
"Richard Greenwell" <lazygun@.gmail.com> wrote in message
news:42b7583d.0406251224.18af1b8@.posting.google.com...
> This is an interesting one.
> We have implemented a custom security extension that we call from
> within an application. We pass in a userid and password into the
> LogonUser method, which is then checked against our database.
> However, we have a Master database, and then a few other small
> databases for different clients, so the extension uses another
> supplied value to go to the master database, and lookup which database
> it needs to verify the user in.
> So, in the RSReportServer.config file, we store the connection string
> to the Master DB.
> This is used to connect to the Master DB, and then lookup the
> connection string for the secondary DB.
> The connection string for the secondary DB uses Integrated
> Authentication (as our application requires this).
> When the Application Pool (in IIS) that ReportServer runs under, is
> set to the NetworkUser, we get an error returned from the WebService
> (called from within our application), which says that the Network
> Service was not authorized to access the secondary DB. Understandable
> :)
> So, we changed the Application Pool, so that it uses a Domain account
> as it's Identity. Now we receive the following error back (and in all
> the log files I can find)..
> System.Web.Services.Protocols.SoapException: An internal error
> occurred on the report server. See the error log for more details.
> -->
Microsoft.ReportingServices.Diagnostics.Utilities.InternalCatalogException:
> An internal error occurred on the report server. See the error log for
> more details. --> System.IO.FileNotFoundException: The system cannot
> find the file specified. at
> System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32
> errorCode, IntPtr errorInfo) at
> RSManagedCrypto.RSCrypto.ExportPublicKey() at
> Microsoft.ReportingServices.Library.ConnectionManager.GetEncryptionKey()
> at Microsoft.ReportingServices.Library.ConnectionManager.ConnectStorage()
> at
Microsoft.ReportingServices.Library.ConnectionManager.VerifyConnection()
> at Microsoft.ReportingServices.Library.ConnectionManager.get_Connection()
> at Microsoft.ReportingServices.Library.Storage.get_Connection() at
> Microsoft.ReportingServices.Library.Storage.NewStandardSqlCommand(String
> storedProcedureName) at
>
Microsoft.ReportingServices.Library.DBInterface.GetOneConfigurationInfo(Stri
ng
> key) at
Microsoft.ReportingServices.Library.CachedSystemProperties.GetSystemProperty
(String
> name) at
Microsoft.ReportingServices.Library.CachedSystemProperties.Get(String
> name) at
Microsoft.ReportingServices.Library.CachedSystemProperties.GetParameter(Stri
ng
> name) at
Microsoft.ReportingServices.Library.RSService.get_MyReportsEnabled()
> at Microsoft.ReportingServices.Library.RSService.PathToInternal(String
> source) at
Microsoft.ReportingServices.Diagnostics.CatalogItemContext.SetPath(String
> path, Boolean validate, Boolean convert, Boolean translate) at
> Microsoft.ReportingServices.Diagnostics.CatalogItemContext.SetPath(String
> path) at
Microsoft.ReportingServices.Diagnostics.CatalogItemContext..ctor(IPathTransl
ator
> pathTranslator, String userSuppliedPath, String parameterName) at
> Microsoft.ReportingServices.Library.RSService.FindItems(String folder,
> String operation, SearchCondition[] properties) -- End of inner
> exception stack trace -- at
> Microsoft.ReportingServices.Library.RSService.FindItems(String folder,
> String operation, SearchCondition[] properties) at
> Microsoft.ReportingServices.WebServer.ReportingService.FindItems(String
> Folder, BooleanOperatorEnum BooleanOperator, SearchCondition[]
> Conditions, CatalogItem[]& Items) -- End of inner exception stack
> trace -- at
Microsoft.ReportingServices.WebServer.ReportingService.FindItems(String
> Folder, BooleanOperatorEnum BooleanOperator, SearchCondition[]
> Conditions, CatalogItem[]& Items)
> The Application Pool User is a member of the IIS_WPG group, and has
> been granted write access to the Windows\Temp folder, and the MSSQL
> folder where RS is installed (and sub folders).
> I also tried adding it to the local machine admin group, and it made
> no difference.
> That user also has DBO access to all the DBs on our database server.
> Can anyone help please?
> Thanks
> Richard|||I have emailed you the log file for this problem.
The user that the application pool runs under does not have an entry
under Docs and Settings, but it is a different user to that which the
Report Server Windows Service runs under, which Does have an entry
under Docs and Settings.
I have never seen an app pool user have a Docs and Settings folder :)
Thank you
Richard
"Brian Hartman [MSFT]" <brianhartman@.hotmail.com> wrote in message news:<OTBYLlYXEHA.748@.TK2MSFTNGP11.phx.gbl>...
> Will you send the report server web service log file?
> Also, can you verify that the new identity has a user profile on the machine
> (the user should have an entry under c:\Documents and Settings)?
> --
> This posting is provided "AS IS" with no warranties, and confers no rights
>
<snip>sql
Tuesday, March 27, 2012
Help with calling a job from Stored P and VBA......HELP
procedure?
I have a DTS that I set as a job and would like to either call it from
an ADP with
Conn.Execute "EXEC msdb..sp_start_job @.job_name = 'Volusia'"
OR just strat it with a stored procedure and call the stored procedure
from the adp
CREATE PROCEDURE sde.Volusia_Import AS
EXEC msdb..sp_start_job @.job_name = 'Volusia_Import'
GO
I tried both of these and it does not give me an error but it does not
run the job... what am I missing?
Thanks,
ChuckHere's a sample that pulls the variable from a form and passes it to a
stored procedure:
'Declare variables
Dim cmd As ADODB.Command
Dim prm As Parameter
'Set connection and command properties
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "spMyProcedure"
'Set parameters
Set prm = cmd.CreateParameter("@.myVariable", adInteger, adParamInput)
cmd.Parameters.Append prm
prm.Value = Forms!myForm.myVariable.Value
'Run Command
cmd.Execute
'Cleanup resources
Set cmd = Nothing
Set prm = Nothing|||(meyvn77@.yahoo.com) writes:
> I would like to know if it is possible to start a job from a stored
> procedure?
Yes. As long as you have the privileges.
> I have a DTS that I set as a job and would like to either call it from
> an ADP with
> Conn.Execute "EXEC msdb..sp_start_job @.job_name = 'Volusia'"
Maybe better to add an adExecuteNoRecords? This could be the reason
you don't see any error message.
> I tried both of these and it does not give me an error but it does not
> run the job... what am I missing?
And SQL Server is running?
Have you checked in job history that the job is not terminating directly?
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp
Wednesday, March 21, 2012
Help with a recursive call
I have a user table and a user_hierarchy table. The hierarchy table list children of the parent users.
ie
create user_hierarchy (
int parent_userid,
int child_userid
)
each parent can have any number of children and each child can in turn have children. so for users 1,2,3,4 you would have::
Parent,Child
1,2
1,3
1,4
1,5
2,3
2,4
3,5
I need a way to get all the children and children's children from a user.
so for user 1, it would give me back 2,3,4,5
for user 2 it would give back 3,4,5 (3 and 4 are direct children) and 5 is a child of 3
I have tried this using Temp tables and Cursors with recursion. The cursors won't work with the recursion and the temp table would be most problematic because this is a web application and I would need to generate unique temp table names for each call. Additionally, I can't seem to find an elegant way to get the children's children without implementing some sort of cursor or stepping algorithm.
Any help would be most appreciated.
Thanks In Advance,
billYou can try something like this:
SELECT INTO #results SELECT child_userid FROM user_hierarchy
WHERE Parent = @.parent
DECLARE @.next_level int
SELECT @.next_level = COUNT (*) FROM user_hierarchy
WHERE parent_userid IN ( SELECT * FROM #results )
AND child_userid NOT IN ( SELECT * FROM #results )
whle @.next_level != 0
Begin
SELECT INTO #results SELECT child_userid FROM user_hierarchy
WHERE parent_userid IN ( SELECT * FROM #results )
AND child_userid NOT IN ( SELECT * FROM #results )
SELECT @.next_level = COUNT (*) FROM user_hierarchy
WHERE parent_userid IN ( SELECT * FROM #results )
AND child_userid NOT IN ( SELECT * FROM #results )
End|||Hi
I have the same kind of problem. I don't know much about SQL.
I have a table parent_child that contains the following fields:
parent_child_id
parent_id
child_id
qty
I need to show the table in hierarchical form.
Parent Child
1 2
1 3
1 4
3 5
3 6
Needs to be displayed as (or as close to):
1 -> 2
-> 3 -> 5
-> 6
-> 4
Any ideas?
Thanks
Trav|||Assuming you have the following table in your database:
user_hierarchy (parent_userid int, child_userid int)
Add the next store proc and function to your database:
1) Function:
CREATE FUNCTION fnChilds (@.parent int, @.comp int, @.lev int)
RETURNS @.T1 TABLE (ParentID int, ChildID int, LevelNo int, DirectParent int)
AS
BEGIN
insert into @.T1 select @.parent,child_userid,@.lev,@.comp from user_hierarchy where parent_userid=@.comp
set @.lev=@.lev+1
declare Crs cursor for
select distinct ChildID from @.T1 order by 1
open Crs
fetch next from Crs INTO @.comp
WHILE @.@.FETCH_STATUS = 0
BEGIN
insert into @.T1 select ParentID, ChildID, LevelNo, DirectParent from dbo.fnChilds(@.parent,@.comp,@.lev)
fetch next from Crs INTO @.comp
END
close Crs
deallocate Crs
return
END
2) Store proc:
CREATE PROCEDURE GetChilds @.parent int AS
declare @.lev int,@.comp int
set @.lev=1
set @.comp=@.parent
select distinct * from dbo.fnChilds(@.parent,@.comp,@.lev) order by LevelNo
In Query Analyzer type:
Exec GetChilds 1 (where 1 is a valid code for a parent)
IONUT
Good look!|||Thanks heaps for that...
How do I display this though using ASP? Is it a matter of just calling the stored procedure or do I have to do something else to make it display the structure on the web?
I ultimately need to have a form that prompts a user for the parent no and then displays the structure for that parent.|||Worked out how to do my last question... Was pretty easy in the end.
However, how can I include the names of the parent and children in my results?
Thanks|||Assuming you have the following table in your database:
users(UserID int,UserName varchar(50))
, change the store proc to this one:
CREATE PROCEDURE GetChilds @.parent int AS
declare @.lev int,@.comp int
set @.lev=1
set @.comp=@.parent
select parent.UserName as ParentName,child.UserName as ChildName,LevelNo,directparent.UserName as DirectParentName
from (select distinct * from dbo.fnChilds(@.parent,@.comp,@.lev)) T
join users as parent on T.ParentID=parent.UserID join users as child on T.ChildID=child.UserID
join users as directparent on T.DirectParent=directparent.UserID
order by LevelNo,child.UserName
IONUT
PS In my opinion the introduction of functions (especially the functions that return a table) is a big step forward for SQLServer.
Beware, at first look, recursivity may seem like a cool thing, because this is exactly what SQL language was not (SQL statement treats all records that they processed as a whole, you can not interfear in the process to make recursive calls). It's true but, on the other hand recursive functions may give you a very strong headache because they are one of the best memory consumption agents, and can easily become a bottleneck for your application if they are used frequently and with large sets of records (to read: with many branches)|||Thanks once again... Now to really test you. Any ideas on how I could display this structure using ASP or something esle in hierarchical form instead of in a table.
It would be easier to read if you could see the branches.
eg.
Assembly 2
Part 1
Part 2
Assembly 1
Part 1
It doesn't have to be done using ASP ... I am just curious if anybody knows a way to show it like this. Even if there is a software package that will display it.
Thanks
Trav|||Just discovered an error... If I have any more than 2 levels I get the following error:
Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).
Is there a way to have an infinite number of levels?
Cheers|||You can't overcome the 32 nested levels limit. Even so, I cant't figure out why it wasn't work afeter level 2?? So, I've changed the store proc and function with another store proc which is not recursive anymore:
Create this store proc in your database:
CREATE PROCEDURE GetChilds1
@.parent int AS
declare @.lvl int,@.cont int
declare @.T1 TABLE (ParentID int, ChildID int, LevelNo int, DirectParent int)
declare @.T2 TABLE (CompID int)
set @.lvl=0
insert into @.T2 values (@.parent)
set @.cont=1
while @.cont<>0
BEGIN
insert into @.T1
select @.parent,child_userid,@.lvl,tbl2.CompID from user_hierarchy tbl1
join @.T2 tbl2 on tbl1.parent_userid=tbl2.CompID
delete from @.T2
insert into @.T2 select distinct ChildID from @.T1 where LevelNo=@.lvl
set @.cont=@.@.rowcount
set @.lvl=@.lvl+1
END
select parent.UserName as ParentName,child.UserName as ChildName,LevelNo,directparent.UserName as DirectParentName
from @.T1 as T join users as parent on T.ParentID=parent.UserID join users as child on T.ChildID=child.UserID
join users as directparent on T.DirectParent=directparent.UserID
order by LevelNo,child.UserName
As for the layout in ASP script, that's your task to handle.
Good luck!
IONUT|||I discovered that I got the error because I added a child that already had the parent as one of its own children.
eg. parent = 4, children = 3, 2, 1
then I created a parent = 3 with children = 4, etc..
Is there an easy way to validate this when I insert records into the parent_child table? I don't have a stored procedure for the insert. I just have an insert statement that inserts a selected parent number into the parent column, and inserts the children as you go but doesn't allow you to insert the same child twice unless the parent number is different.
eg. I select parent = 4 and start adding children.
Parent Child
4 1
4 2
4 3
Sorry I don't know enough about writing stored procedures, functions, etc, and this is the only way I could come up with.|||It's more simple than to create store procedure or function. You simply decalre the primary key for the parent_child table as ParentID,ChildID. Or, if you already have another primary key for that table, you can declare an unique index on those two fields.
IONUT
PS Once you do that the only thing that you have to implement is a error check procedure (in your ASP code), in case that insert statement failed because of duplicates entries. (see the result that the execute method returns, for the command object that you used in vbscript)|||Sorry I don't really understand what you mean? I didn't think I could have a primary key in this parent_child table?
I need to be able to look all the way down a tree structure. Say I am inserting parent no = 6 with child no =3, but child no = 3 already exists as a parent with child no = 6.
It is okay to validate this but it gets tricky if parent no = 3 only contains child no = 4, but child no = 4 is a parent to child no = 6.
This is very confusing I know but I'd really appreciate any suggestions or stored procedures that will resolve this problem.
Thanks
Trav|||You can create a trigger (INSERTS and UPDATES) for your parentchild table, something like this:
if ((select count(*) from parent_child inner join inserted on parent_child.ParentID=inserted.ParentID and parent_child.ChildID=inserted.ChildID)+(select count(*) from parent_child inner join inserted on parent_child.ParentID=inserted.ChildID and parent_child.ChildID=inserted.ParentID))>0
ROLLBACK TRANSACTION
else
COMMIT TRANSACTION
ionut|||Thank... I created this trigger and it wouldn't allow me to do any inserts. I figured it was because the condition would not commit the transaction if the count > 0. So I changed it to count > 1 and this works fine, except I still have the problem that it will allow me to insert a child that is a parent which already contains this same parent some where down the line that I am inserting.
I have the following table:
P C
3 1
3 4
4 6
Then if I try to add item 6 as a parent with a child = item 3, I shouldn't be able to. It shouldn't let me do this because parent = 3 actually already contains item no 6 sitting under its other child no 4.
It doesn't matter how many branches down the tree I go, I shouldn't be able to add a child to a parent if that child already exists as a parent else where, and it contains this same parent I am creating as a child, grandchild, great grand child, etc, somewhere in its tree structure.
Sorry I am not explaining it very well... It is confusing.
Monday, March 19, 2012
Help with a Problem:Reporting Services Session Management
I have a Report Image that I call from Reporting Services and I render it in
a Sharepoint Webpart, I need to manage the Session from reporting sevices as
when I try to manage it from the Sharepoint Web Part, Reporting Services says
it can not find the image/data, as the report session has changed, and has
new data, I need to make the Report Image Session able to maintain the prior
session.
I was wondering if there was a way to capture the session variable from
Reporting Services and keep it in the webpart? or capture it in someway to to
maintain the sessionon the data call.
Any one out there know how to capture this or have run into this problem, or
might know a solution?
If you are using the Reporting Services Web Service to retrieve the report by calling the Render method on the ReportingService object in your web part, you can capture the Report SessionId from the SessionHeaderValue.SessionId property on the ReportingSe
rvice object after the call and use it later when you are retrieving the image via the RenderStream method.
see: http://msdn.microsoft.com/library/de...ce_lz_6x0z.asp
Currently I am using a Web Part to display the report and a seperate .aspx file to render the images in the report.
I call the Render Method of the Web Service with the and set the deviceinfo for HTMLFragment(true),StreamRoot(/myVirtualDirectory/ImageRender.aspx?sessionid=&reportname=xx¶m1=y y&streamid=)
After the call the output html will contain image tags with src attribute equal StreamRoot concatinated with the streamId (i.e. streamid has to be the last item in the query string)
I populate the sessionid in the above image url with a string replace.
CODE:
public static string RetrieveReport(string reportPath, ParameterValue[] parameterValues, string sharePointHelperUrl, bool useDefaultCredentials)
{
string outputHtml=string.Empty;
ReportingService rs = new ReportingService();
rs.Credentials = GetCredentials(useDefaultCredentials);
ItemTypeEnum reportType = rs.GetItemType(reportPath);
if(reportType==ItemTypeEnum.Report)
{
// Render arguments
byte[] result = null;
// Prepare Render method's parameters.
/*
* The devInfo parameter is set to hide the tool bar, hide the parameters, return the fragment Html
* and prefix all images with the Url to our helper aspx file with the query string holding all data
* required to retrieve the correct image from the Reporting Service
* */
string imageUrl = System.Web.HttpUtility.HtmlEncode(
string.Format("{0}/getreportimages.aspx?{1}={2}&{3}={4}&{5}={6}&{7}=" ,
sharePointHelperUrl,
"RSSessionID",
"",
"ReportPath",
reportPath,
"Parameters",
getReportParametersForQueryString(parameterValues) ,
"StreamID"
)
);
string devInfo = @."<DeviceInfo><Toolbar>False</Toolbar><StreamRoot>" + imageUrl + "</StreamRoot><Parameters>False</Parameters><HTMLFragment>True</HTMLFragment></DeviceInfo>";
string format = "HTML4.0";
string historyID = null;
DataSourceCredentials[] credentials = null;
string showHideToggle = null;
string encoding;
string mimeType;
Warning[] warnings = null;
ParameterValue[] reportHistoryParameters = null;
string[] streamIDs = null;
rs.SessionHeaderValue = new SessionHeader();
result = rs.Render(reportPath, format, historyID, devInfo, parameterValues, credentials, showHideToggle, out encoding, out mimeType, out reportHistoryParameters, out warnings, out streamIDs);
outputHtml = System.Text.Encoding.UTF8.GetString(result, 0,result.Length);
/*
* The SessionHeaderValue.SessionId is not available until the Render method of the Reporting Service
* has been called. This is required when calling the RenderStream method, this method is called by the
* supporting aspx page. This page is requested by the client to render images. Replace Query String
* "RSSessionID" with "RSSessionID" and the SessionHeaderValue.SessionId for each image in the rendered
* output.
* */
outputHtml = outputHtml.Replace("RSSessionID=", "RSSessionID=" + rs.SessionHeaderValue.SessionId);
}
return outputHtml;
}
NOTE:The /myVirtualDirectory/ has to excluded from SharePoint so it is processed as a normal aspx.
************************************************** ********************
Sent via Fuzzy Software @. http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...