logo

Warning: The forum is now for consultation only. Please use GitHub Discussions to post any questions or comments.


Welcome Guest ! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
cyracks  
#1 Posted : Tuesday, June 23, 2020 3:05:13 PM(UTC)
cyracks

Rank: Member

Groups: Registered
Joined: 6/5/2020(UTC)
Posts: 12
Slovenia

Thanks: 4 times
Hello,

what is the name of a variable that can be inserted in SQL model and will be replaced with logged in user name ?
Example of usage:
Quote:
exec sp_storedprocedure @username = {?}



I also tried the following:
https://sealreport.org/f...t.aspx?g=posts&t=157
Quote:

@{
ReportModel model = Model;
string UserWeb = model.Report.SecurityContext.WebUserName;
string result = "select '"+UserWeb+"'";
}
@Raw(result)


But error "Object reference not set to an instance of an object."
(I can not do security limitation in Additional WHERE Clause, it is way to rigid for my scenario)


Regards,
Tomaž

Edited by user Friday, June 26, 2020 9:25:30 AM(UTC)  | Reason: Not specified

cyracks  
#2 Posted : Friday, June 26, 2020 3:43:19 PM(UTC)
cyracks

Rank: Member

Groups: Registered
Joined: 6/5/2020(UTC)
Posts: 12
Slovenia

Thanks: 4 times
I finally figure it out. I found two options:

1) Pre SQL statement in Metadata model - executed before SQL model
Quote:

@using Seal.Model
@{
ReportModel model = Model;
var userWeb = "";
if (model.Source.Report != null && model.Source.Report.SecurityContext != null){
var securityContext = model.Source.Report.SecurityContext;
userWeb = securityContext.WebUserName;
}

string result =
"if object_id('tempdb..#tFilter', 'U') is not null "+
" drop table #tFilter "+
"create table #tFilter (name varchar(25), value nvarchar(1024)) "+
"insert into #tFilter(name, value) "+
"values('user_web', '"+userWeb+"') "

;
}
@Raw(result)


2) Pre SQL statement in data source repository - executed before every SQL query
Quote:

@using Seal.Model
@{
MetaSource source = Model;
var userWeb = "";
if (source.Report != null && source.Report.SecurityContext != null){
var securityContext = source.Report.SecurityContext;
userWeb = securityContext.WebUserName;
}

string result =
"if object_id('tempdb..#tFilter', 'U') is not null "+
" drop table #tFilter "+
"create table #tFilter (name varchar(25), value nvarchar(1024))"+
"insert into #tFilter(name, value) "+
"values('user_web', '"+userWeb+"') "
;
}
@Raw(result)

Edited by user Friday, June 26, 2020 4:41:20 PM(UTC)  | Reason: Not specified

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.