Showing posts with label current. Show all posts
Showing posts with label current. Show all posts

Thursday, March 22, 2012

CurrentMember and a set

I have an excel sheet that people are using with pivot tables. The users want to be able to select a set of dates, and get a current year measure, along with the corresponding last year measures on a day to day comparison (not day of year, or date vs. date, but a "monday this year vs. monday last year", which is 364 days ago). They want to be able to pick and choose which days go into the set, for instance they want 1/1/cy, 2/1/cy, 2/5/cy and the sum of a measure vs. 1/2/ly, 2/2/ly, and 2/6/ly same measure summed up.

I can do this for a single selection (using ([Calendar].[Date].CurrentMember.Lag.(364), [Measure]), but I don't know how to access a list of items in the calcluated measure when they select a set.

If I could write this in MDX it would be much easier, but they would like to have control over it and do it through Excel (who can blame them?).

Does anyone have any suggestions?

thank you in advance,

John Hennesey

Assuming that you're using AS 2005, which version of Excel is involved (2003 issues different multi-select MDX queries than 2007)?|||

Sorry I left that detail out. I am using Excel 2003.

Thanks in advance,

John

|||

Hi John,

With Excel 2003, you should be able to use the "Existing" approach, discussed in Mosha's blog:

http://sqljunkies.com/WebLog/mosha/archive/2005/11/18/multiselect_friendly_mdx.aspx

>>

Writing multiselect friendly MDX calculations

...

But obviously we wanted AS2005 to work well with existing client tools too. Therefore, AS's query engine recognizes the shape of the queries where there is query calculated member doing Aggregate over constant single grain set, and this calculated member (or members if there are multiple multiselects in different hierarchies) is in the WHERE clause. And when AS detects this situation, it replaces the calculated member in the WHERE clause with the corresponding set.

...

>>

So, in your scenario, the calculated measure MDX expression could be like:

Aggregate(Generate(Existing [Calendar].[Date].[Date], {[Calendar].[Date].Lag(364)}), [Measure])

|||

Awesome - thank you very much for the response. I will give it a shot. One question - when it iterates through the currently selected set, how will it know which ones are selected? Should the first [Calendar].[Date].[Date] be [Calendar].[Date].CurrentMember? If this is a dumb question, please forgive me - I'm still fairly new to MDX.

Once again, thanks!

John

|||

"when it iterates through the currently selected set, how will it know which ones are selected?" - Mosha's blog entry above explains this better than I could.

"Should the first [Calendar].[Date].[Date] be [Calendar].[Date].CurrentMember" - no, this is the [Date] level of the [Calendar].[Date] hierarchy, and is shorthand for [Calendar].[Date].[Date].Members, which you can use instead. This all applies if you're using AS 2005, of course.

|||Cool - I will dig into Mosha's blog. Thank you for your quick response!

currentdate and monthtodate help!

Hi,

I'm trying to make a report that calculates the sales for some products,
it should show the sales of the current date inaddition to the sales of month to date on one line. This seems easy but the problem is when I'm trying to put a formula for the current time the system is taking the first records' date only, and ignoring other invoices dates.
Well gurus, where could be the problem, I tried to change the linking with no use...!

thanks in advance,,,,,,,Can you explain this little bit more with some real data example

and from your question only thing I found is you need Sales group by Month Am I correct ??

If yes... use group by function for Monthly Sales

Current Year Data

I have an MDX DataSet that gets the data for 2007 (hard coded). I want to automate it to get the current year data so that I don't have to manually update the code in 2008.

The data set is as follows:

SELECT NON EMPTY {[Measures].[Fixtures]} ON COLUMNS,

NON EMPTY {( [Charterer].[Current Short Code].[Current Short Code].ALLMEMBERS )} ON ROWS

FROM ( SELECT ( { ([CP Date].[Year].&[2007]) } ) ON COLUMNS FROM [Voyage Analysis])

I got as far as being able to find the current year

WITH MEMBER [Measures].[ThisDay] AS Now()

MEMBER [Measures].[ThisYear] AS 'YEAR([ThisDay])'

SELECT {[ThisDay],[ThisYear]} ON COLUMNS

FROM [Voyage Analysis]

But I have no idea how to replace "&[2007]" with , "[ThisYear]".

As you can see I'm not very experienced with MDX, appreciate if anyone can help.

Thanks

Richard

You could build a string version of the year member, then use StrToMember():

SELECT NON EMPTY {[Measures].[Fixtures]} ON COLUMNS,

NON EMPTY {( [Charterer].[Current Short Code].[Current Short Code].ALLMEMBERS )} ON ROWS

FROM ( SELECT ( { StrToMember("[CP Date].[Year].&["

+ CStr(Year(Now())) + "]") } ) ON COLUMNS FROM [Voyage Analysis])

|||

Thanks. Perfect!

Richard

Current Year

Hi,
I am new at T-SQL.
I need to access a table with the field inv_dt.
I need the sum of the invoices where it takes only the sum of the current
year invoices.
When 2006 arrives I only want the sum of 2006 invoices without having to
rewrite the code for each year that rolls around.
Any help would be appreciated.
Thanks,
TerryHi, Terry
Try something like this:
SELECT SUM(ammount) FROM invoices
WHERE YEAR(inv_dt)=YEAR(GETDATE())
Razvan|||SELECT SUM(Col)
FROM YourTable
WHERE
inv_dt >= DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)
AND inv_dt < DATEADD(yy, DATEDIFF(yy, 0, GETDATE())+1, 0)
Adam Machanic
Pro SQL Server 2005, available now
http://www.apress.com/book/bookDisplay.html?bID=457
--
"newbi" <twillett@.cox-internet.com> wrote in message
news:Vapgf.24167$4l5.6904@.dukeread05...
> Hi,
> I am new at T-SQL.
> I need to access a table with the field inv_dt.
> I need the sum of the invoices where it takes only the sum of the current
> year invoices.
> When 2006 arrives I only want the sum of 2006 invoices without having to
> rewrite the code for each year that rolls around.
> Any help would be appreciated.
> Thanks,
> Terry
>|||DECLARE
@.firstOfThisYear SMALLDATETIME,
@.firstOfNextYear SMALLDATETIME
SET @.firstOfThisYear = CONVERT(CHAR(4), YEAR(CURRENT_TIMESTAMP))+'0101'
SET @.firstOfNextYear = DATEADD(YEAR,1,@.FirstOfThisYear)
SELECT SUM(amount)
FROM invoices
WHERE inv_dt >= @.firstOfThisYear
AND inv_dt < @.firstOfNextYear
Now if inv_dt has an index, you can use it.
"newbi" <twillett@.cox-internet.com> wrote in message
news:Vapgf.24167$4l5.6904@.dukeread05...
> Hi,
> I am new at T-SQL.
> I need to access a table with the field inv_dt.
> I need the sum of the invoices where it takes only the sum of the current
> year invoices.
> When 2006 arrives I only want the sum of 2006 invoices without having to
> rewrite the code for each year that rolls around.
> Any help would be appreciated.
> Thanks,
> Terry
>|||Careful with that one, Razvan -- since you're using a function on the column
the query can't be satisfied using an index s.
Adam Machanic
Pro SQL Server 2005, available now
http://www.apress.com/book/bookDisplay.html?bID=457
--
"Razvan Socol" <rsocol@.gmail.com> wrote in message
news:1132601271.210016.241970@.g44g2000cwa.googlegroups.com...
> Hi, Terry
> Try something like this:
> SELECT SUM(ammount) FROM invoices
> WHERE YEAR(inv_dt)=YEAR(GETDATE())
> Razvan
>|||Thanks Guys,
That worked perfectly.
Terry
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:eRtAxHt7FHA.2176@.TK2MSFTNGP14.phx.gbl...
> SELECT SUM(Col)
> FROM YourTable
> WHERE
> inv_dt >= DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)
> AND inv_dt < DATEADD(yy, DATEDIFF(yy, 0, GETDATE())+1, 0)
> --
> Adam Machanic
> Pro SQL Server 2005, available now
> http://www.apress.com/book/bookDisplay.html?bID=457
> --
>
> "newbi" <twillett@.cox-internet.com> wrote in message
> news:Vapgf.24167$4l5.6904@.dukeread05...
>|||> Careful with that one, Razvan -- since you're using a function on the columnd">
> the query can't be satisfied using an index s.
Yes, indeed. But probably, we won't have more than 5-10 years of data
in the table, so an index scan would be used anyway. Anyway, you are
correct that your query is preferable, because the optimizer has more
options available.
Razvan

current users

Is there a limit on how many concurrent users that can use SQL Server 2005 Express Edition?

I haven't been able to find any facts about that

Hi,

no there isn′t and there never has been. MSDE either didn′t havelimited concurrent users, the workload governor only throttled the query performance for more than 5 users.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||

Jens is correct, we do not limit the number of concurrent users in SQL Express. We have also removed the workload governer in SQL Express as well. Check out Euan Garden's Blog for a historical discussion on the workload governer in MSDE.

http://blogs.msdn.com/euanga/archive/2006/03/09/545576.aspx

Mike - SQL Express team

sql

Current User Roles List seems Incorrect

Our app uses the ROLES column of the CATALOGS rowset from the schema, and I seem to be seeing what I think are incorrect results.

The documenation says "Username is appended to ROLES if one of the roles uses dynamic security". OK.

But I often get the username even when there are no MDX expressions used for dimension or cell access. For example, every Foodmart 2000 cube I have migrated shows the username in the role list.

What is the definition of dynamic security for the purposes of the CATALOGS rowset?

I should have noted, this is SSAS 2005.

This is generally how I am retrieving the roles list, if any one wishes to replicate.

OleDbConnection conn = new OleDbConnection( "provider=msolap;SSPI=Negotiate;Prompt=1" ); conn.Open(); DataTable schema = conn.GetSchema("Catalogs"); foreach(DataRow row in schema.Rows) { if (row["ROLES"].ToString().Length > 0) // only available for the current catalog txtRoles.Text = row["ROLES"].ToString(); } conn.Close();

Current user in SQL

Hi

Is there a variable or a possibility to use the current user in sql?

I would like to create an update trigger and write the user that made the change in the affected table!

Thanks!

Try SUSER_NAME() for the login or USER_NAME() for the database user.

|||

Pick your poison ;-)

SELECT SUSER_SNAME(),USER_NAME(),CURRENT_USER


Denis The SQL Menace
http://sqlservercode.blogspot.com
http://sqlblog.com/blogs/denis_gobo/default.aspx

Current user

Am using SQL Server 2000, and am writing some audit triggers. How do I get
the the name of the user, eg. user_id or current_user. Just spent an hour
looking through the SAMS book for this, and can't find any reference."William F. O'Neill" <wfoneill@.bellsouth.net> wrote in message
news:Clg9d.183017$Np2.110030@.bignews4.bellsouth.ne t...
> Am using SQL Server 2000, and am writing some audit triggers. How do I
> get the the name of the user, eg. user_id or current_user. Just spent an
> hour looking through the SAMS book for this, and can't find any reference.

select user_name()|||Thank you ParrotRob, but that gives me 'dbo.' If I log on to my
application, I want to be able to capture 'my' logon id, eg. wfoneill.
Remember, I want to be able to use this in my Insert, Update, & Delete
triggers.
Bill...

"ParrotRob" <parrotrob@.yahoo.com> wrote in message
news:c8udneeR2ZtXm_vcRVn-vQ@.adelphia.com...
> "William F. O'Neill" <wfoneill@.bellsouth.net> wrote in message
> news:Clg9d.183017$Np2.110030@.bignews4.bellsouth.ne t...
>> Am using SQL Server 2000, and am writing some audit triggers. How do I
>> get the the name of the user, eg. user_id or current_user. Just spent an
>> hour looking through the SAMS book for this, and can't find any
>> reference.
> select user_name()|||William F. O'Neill wrote:
> Am using SQL Server 2000, and am writing some audit triggers. How do
> I get the the name of the user, eg. user_id or current_user. Just
> spent an hour looking through the SAMS book for this, and can't find
> any reference.

You have:

CURRENT_USER
USER_NAME()
SUSER_SNAME()

If you get frustrated building audit triggers, you can look at our OmniAudit
product for doing exactly that:

http://www.krell-software.com/omniaudit

--
Steve Troxell|||The SAMS book is a good resource for learning how to user SQL Server but
isn't a great resource for looking things like this up. You can more
readily get the answer you need by getting familiar with SQL Server Books On
Line (BOL). Install or reinstall the tools on your desktop machine and load
all the documentation to your hard disk for best performance (and
availability). There is an option to use BOL off the CD but it will be
slower and whenever you want to use BOL, you'll have to remove your music CD
(and I just hate doing that).

Then, this problem will depend on how the users are connecting to the
database. If you're using an application UserID (where the credentials for
the connection are actually buried in the app and are the same for each
user), then you won't get much information about the individual who's
actually using the application. However, if you're using trusted
connections or you've set up SQL Server LogonIDs for each user, you could
see if:

select suser_sname()

- or -

select system_user

gives you the result you want. I think there are also some global variables
that you could examine to see if they'll help you.

Really, time spent in BOL getting familiar with how to find things is not
time wasted. Remember that whenever you hit a topic, you should check the
"See Also" list at the bottom of each page.

"William F. O'Neill" <wfoneill@.bellsouth.net> wrote in message
news:Clg9d.183017$Np2.110030@.bignews4.bellsouth.ne t...
> Am using SQL Server 2000, and am writing some audit triggers. How do I
get
> the the name of the user, eg. user_id or current_user. Just spent an hour
> looking through the SAMS book for this, and can't find any reference.|||Thanks for all the help, and suggestions.

"DHatheway" <dlhatheway@.mmm.com.nospam> wrote in message
news:ck67rd$qc$1@.tuvok3.mmm.com...
> The SAMS book is a good resource for learning how to user SQL Server but
> isn't a great resource for looking things like this up. You can more
> readily get the answer you need by getting familiar with SQL Server Books
> On
> Line (BOL). Install or reinstall the tools on your desktop machine and
> load
> all the documentation to your hard disk for best performance (and
> availability). There is an option to use BOL off the CD but it will be
> slower and whenever you want to use BOL, you'll have to remove your music
> CD
> (and I just hate doing that).
> Then, this problem will depend on how the users are connecting to the
> database. If you're using an application UserID (where the credentials
> for
> the connection are actually buried in the app and are the same for each
> user), then you won't get much information about the individual who's
> actually using the application. However, if you're using trusted
> connections or you've set up SQL Server LogonIDs for each user, you could
> see if:
> select suser_sname()
> - or -
> select system_user
> gives you the result you want. I think there are also some global
> variables
> that you could examine to see if they'll help you.
> Really, time spent in BOL getting familiar with how to find things is not
> time wasted. Remember that whenever you hit a topic, you should check the
> "See Also" list at the bottom of each page.
> "William F. O'Neill" <wfoneill@.bellsouth.net> wrote in message
> news:Clg9d.183017$Np2.110030@.bignews4.bellsouth.ne t...
>> Am using SQL Server 2000, and am writing some audit triggers. How do I
> get
>> the the name of the user, eg. user_id or current_user. Just spent an
>> hour
>> looking through the SAMS book for this, and can't find any reference.
>>
>>

Current User

How can get the current user name/id of the connected user in Sql
Server 2005? I am using windows authentication. If I use USER or
CURRENT_USER function it always returns DBO and I am looking for the
network sign on which in my case would be URSC. Thanks.Try the ORIGINAL_LOGIN() function.
Hope this helps.
Dan Guzman
SQL Server MVP
"S Chapman" <s_chapman47@.hotmail.co.uk> wrote in message
news:1150200242.086128.219900@.p79g2000cwp.googlegroups.com...
> How can get the current user name/id of the connected user in Sql
> Server 2005? I am using windows authentication. If I use USER or
> CURRENT_USER function it always returns DBO and I am looking for the
> network sign on which in my case would be URSC. Thanks.
>|||Try using SUSER_SNAME. See BOL for more info.
AMB
"S Chapman" wrote:

> How can get the current user name/id of the connected user in Sql
> Server 2005? I am using windows authentication. If I use USER or
> CURRENT_USER function it always returns DBO and I am looking for the
> network sign on which in my case would be URSC. Thanks.
>|||"S Chapman" <s_chapman47@.hotmail.co.uk> escribi en el mensaje
news:1150200242.086128.219900@.p79g2000cwp.googlegroups.com...
> How can get the current user name/id of the connected user in Sql
> Server 2005? I am using windows authentication. If I use USER or
> CURRENT_USER function it always returns DBO
If the user is admin, you will get dbo
Peter

current updated value in table

hello all..

i want to update my table information with the value which is currently inserted/updated in another table dynamically..how to get the value of a currently inserted single cell in that table..?

table1 contains Refno,....Refno is primarykey,identity

table 2 contains uploadID,...uploadID is primary key,identity

table3 contains RefNo,UploadID(both r foriegn keys corresponding to table1 & table2)

how to fill table3 with values(not manually) when i am inserting records into table1 n table2 ..( refno and uploadId are identity columns )..Any Idea..?

thanks in Advance

Anne

hello anne..,

are u use sqldatasource to insert table1 and 2? if yes, in sqldatasource ,u can add query insert like this:

insert into [table3] ([refno],[uploadid]) values (@.refno,@.uploadid)

ok.. let's try it..

:)

|||

Hello hardy,

tranks for ur responce..i think i didn`t explained my requirement well...Actually i am doing some workflow application...in that app i hav one report Incident/Problem page...users has to enter the details regarding their incidents/problems....after submit click i hav to store the form information in Table....The form contains user,date occured,Application,Module,Description and 3 file uploads.....so now to store form info in database i created two tables...Submit (Refno,date,Application,Module,Description), Upload (UploadID,MIMEType,ImageData)......

In the above two tables RefNo ,UploadID are primary keys and identity columns....so no need to insert values in thses two columns explictly as these are identity columns..I used sqldatasource to insert the remaining info into the that tables...

while retriving i need information from the two tables..so i need one more table to relate these two tables...then i created one more table UploadRelate(Refno,uploadID)...both these columns are foriegn keys corresponding to two tables simultaneously....

my plan is to insert values into third table whenever values r inserted into other two tables...so that while retriving i can get the correct uploaded files for the corresponding user.....mySubmit, ,Upload,UploadRelate tables has to look like this after inserting values........

RefNo : user : date : application : Module: Description UploadID:MIMEType:ImageData RefNo : UploadID

1 a 1/1/07 sas sdas dsdd 1 jpg Binary 1 : 1

2 b -- -- -- -- 2 bmp -- 1 : 2

3 c -- -- -- -- 3 txt -- 1 : 3

4 d -- -- -- -- 4 jpg -- 2 : 4

5 doc -- 2 : 5

......user may upload 1 file or 2 files or 3 files..So now the problem is to insert the values in to 3rd table....whenever the other two tables r inserted with values my 3rd one has to be inserted...Is it the correct way to store in 3 tables like this or can i achive my requirement in any other way..?if my oproach is ok...then how to get the value of currently inserted column value from table...?...

insert into [table3] ([refno],[uploadid]) values (@.refno,@.uploadid) can be used ..but the thing is how to get the values of @.refno,@.uploadid...from the other two tables?

Thanks in Advance

AnneSmile

|||

hello...

i am not undestand about ur third table like:

refno : uploadid

1 : 1

1 : 2

1 : 3

2 : 4

2 : 5

why the 1 relation with 1,1 with 2, 1 with 3..

u can not do like that..

emmm... i know..

u must use normalize if u want create table... like this:

ur 3rd table can be delete, so u have 2 table,but add uploadid in table one like this:

mysubmit table:

RefNo uploadid user date application Module Description

1 1 a 1/1/07 sas sdas dsdd

1 2 a 1/1/07 sas sdas dsdd

upload table:

UploadID MIMEType imageData

1 jpg Binary

2 bmp --

so u don't need create 3rd table, but u can call that data from two table...

ok..., let's try it...

the first important thing if u want to make table, u must understand about normalize..

|||

You can. However since there is a one-to-many relationship here instead of a many-to-many relationship, you can place the RefNo directly in the Upload Table (Since each upload must have one and only one RefNo).

That should greatly simplify your application logic.

|||

Thank u for the replies Hardy and Motley...

|||

Hello..

i am getting some problem regarding the above requirement...i am able to enter the data in my first table ,but when i am trying to enter data in second (upload) table i am not able to get the currently inserted refno from first table..my storedprocedure for second table is

ALTER PROCEDUREdbo.UploadInsert

(

@.TitleVarchar(50),

@.MMIETypevarchar(50),

@.ImageDataimage

)

AS

BEGIN

set nocount on

declare@.Ref_Noint

select@.Ref_No=@.@.IDENTITYfromdbo.Submit

INSERT INTO[upload]

([Title],[MMIEType], [ImageData],Ref_No)

VALUES(@.Title,@.MMIEType, @.ImageData,@.Ref_No)

end

RETURN

--Ref_No value is becoming null while inserting into upload table..is it the correct way to get the identity value from submit table ...? in submit table records r entering corrrectly...

Pls i need help..

anne

|||

yes i got the solution...i am doing mistake in my submit storedprocedure...without returning identity value i am retuning 0..so i am not able to get the refno into second table...

AnyHow Thanks to all

anne

sql

Wednesday, March 21, 2012

Current Time of SQL-Server

Hi

is there a "SQL string" to obtain date and time of a SQLServer machine ?

thank uOn Mon, 15 Sep 2003 17:45:48 GMT in comp.databases.ms-sqlserver,
"Solli" <fabioslm@.tiscali.it> wrote:

>Hi
>is there a "SQL string" to obtain date and time of a SQLServer machine ?

GetDate()

--
A)bort, R)etry, I)nfluence with large hammer.

(replace sithlord with trevor for email)

Current Time

Hi. I have a critical design issue. Not a regular time dimension case.

i work for a set of schools where each school academic has a different academic calendar. say some schools start in august, others in september.. i generated the date keys per school to populate the time dimension. so my time dimension looks like this:

DATE_KEY,

DATE_SCHOOL,

DATE_DATE,

DATE_YEAR,

DATE_MONTH,

DATE_WEEK,

DATE_DAY_NUMBER,

DATE_FISCAL_ACAD_YEAR,

DATE_FISCAL_TERM, DATE_FISCAL_WEEK,

DATE_FISCAL_WEEKDAY_NUMBER,

DATE_FISCAL_ACAD_YEAR_DAY_NUMBER,

DATE_HOLIDAY, (y/n)

DATE_WEEKEND, (y/n)

DATE_DAY_NAME,

DATE_FISCAL_TERM_FIRST_DAY,

DATE_FISCAL_TERM_LAST_DAY,

DATE_FISCAL_WEEK_FIRST_DAY,

DATE_FISCAL_WEEK_LAST_DAY

I need help in finding a design to get the current term/current week/current day so that a school manager would get his current's school week's data or term data when he logs in to the system.

Thanks

Could it be that there are only a few sets of dates applicable? In which case you could create Calendars listing the relevant dates and link this back to the school.|||

I added fields to the schools dimension stating the current acad year, term,week,and day per school. and these fields are to be updated at each ETL process. I will use them in the queries.

thanks

Current SQL Statements for database instance

Hi,
In Oracle I have the option as DBA to view what current SQL Statements
is being executed for the current sessions on a database instance. How
do I do this in SQL Server 2005?
The reason is that I have to tune up SQL statements run by binary
executable files for which I don't have the source.
Best regards.Morten
You can turn on SQL Server Profiler and set up a trace to see what is going
on
select
s.session_id,
s.login_name,
s.status session_status,
s.cpu_time session_cpu,
s.logical_reads session_logical_reads,
s.reads session_reads,
s.writes session_writes,
sql_details.objectid session_current_procedure,
object_name(sql_details.objectid) session_current_procedure_name,
sql_details.text session_current_sql_text
from sys.dm_exec_sessions s
join sys.dm_exec_requests req
on s.session_id = req.session_id
cross apply sys.dm_exec_sql_text(req.sql_handle) sql_details
where s.session_id <> @.@.spid
"Morten Abildgaard" <mortenabildgaard@.gmail.com> wrote in message
news:1193213575.893092.10980@.i38g2000prf.googlegroups.com...
> Hi,
> In Oracle I have the option as DBA to view what current SQL Statements
> is being executed for the current sessions on a database instance. How
> do I do this in SQL Server 2005?
> The reason is that I have to tune up SQL statements run by binary
> executable files for which I don't have the source.
> Best regards.
>|||Thanks a bunch, Uri!
The SQL Server Profiler util was exactly what I was looking for. I
just thought it was an integrated part of the Management Studio.
On 24 Okt., 10:43, "Uri Dimant" <u...@.iscar.co.il> wrote:
> Morten
> You can turn on SQL Server Profiler and set up a trace to see what is going
> on
> select
> s.session_id,
> s.login_name,
> s.status session_status,
> s.cpu_time session_cpu,
> s.logical_reads session_logical_reads,
> s.reads session_reads,
> s.writes session_writes,
> sql_details.objectid session_current_procedure,
> object_name(sql_details.objectid) session_current_procedure_name,
> sql_details.text session_current_sql_text
> from sys.dm_exec_sessions s
> join sys.dm_exec_requests req
> on s.session_id = req.session_id
> cross apply sys.dm_exec_sql_text(req.sql_handle) sql_details
> where s.session_id <> @.@.spid
> "Morten Abildgaard" <mortenabildga...@.gmail.com> wrote in message
> news:1193213575.893092.10980@.i38g2000prf.googlegroups.com...
> > Hi,
> > In Oracle I have the option as DBA to view what current SQL Statements
> > is being executed for the current sessions on a database instance. How
> > do I do this in SQL Server 2005?
> > The reason is that I have to tune up SQL statements run by binary
> > executable files for which I don't have the source.
> > Best regards.

Current SQL Server Logs

I am not able to open the current sql server log file from
enterprise manager in one of my servers. I can open the
archive logs below the current one in enterprise server.
When I double click the current log to open it hangs
everything. What is going on on this server, any help
please.Aboki,
Try recycling the error log using sp_cycle_errorlog
--
Dinesh.
SQL Server FAQ at
http://www.tkdinesh.com
"Aboki" <waco361@.hotmail.com> wrote in message
news:0bda01c36b22$517e07e0$a501280a@.phx.gbl...
> I am not able to open the current sql server log file from
> enterprise manager in one of my servers. I can open the
> archive logs below the current one in enterprise server.
> When I double click the current log to open it hangs
> everything. What is going on on this server, any help
> please.

Current Security Context Not Trusted When Using Linked Server From SAP

Hello,

I am experiencing a head-scratcher of a problem when trying to use a Linked Server connection to query a remote SQL Server database from our SAP R/3 system. We have had this working just fine for some time, but after migrating to new hardware and upgrading OS, DBMS, and R/3, now we are running into problems.

The target database is a named instance on SQL Server 2000 SP3, Windows 2000 Server. The original source R/3 system was also on SQL Server 2000 (SP4), Windows 2000 Server. I had been using a Linked Server defined via SQL Enterprise Manager (actually defined when the source was on SQL Server 7), which called an alias defined with the Client Network Utility that pointed to the remote named instance. This alias and Linked Server worked great for several years.

Now we have migrated our R/3 system onto new hardware, running Windows Server 2003 SP1 and SQL Server 2005 SP1. I redefined the Linked Server on the new SQL 2005 installation, this time avoiding the alias and referencing the remote named instance directly, and it tests out just fine using queries from SQL Management Studio. It also tests fine with OSQL called from the R/3 server console, both when logged on as the application service account with a trusted connection, and with a SQL login as the schema owner. From outside of the application, I cannot make it fail. It works perfectly.

That all changes when I try to use the Linked Server within an SAP custom program (ABAP), however. The program crashes with a database interface error. The database error code is 15274, and the error text is "Access to the remote server is denied because the current security context is not trusted."

I have set the "trustworthy" property on the R/3 database, I have ensured the service account is a member of the sysadmin SQL role, I've even made it a member of the local Administrators group on both source and target servers, and I've done the same with the SQL Server service account (it uses a domain account). I have configured the Distributed Transaction Coordinator on the source (Win2003) system per Microsoft KB 839279 (this fixed problems with remote queries coming the other way from the SQL2000 system), and I've upgraded the system stored procedures on the target (SQL2000) system according to MS KB 906954. I also tried making the schema user a member of the sysadmin role, but that was disastrous, resulting in an instant R/3 crash (don't try this in production!), so I set it back the way it was (default).

What's really strange is no matter how I try this from outside the R/3 system, it works perfectly, but from within R/3 it does not. A search of SAP Notes, SDN forums, SAPFANS, Microsoft's KnowledgeBase, and MSDN Forums has not yielded quite the same problem (although that did lead me to learning about the "trustworthy" database property).

Any insight someone could offer on this thorny problem would be most appreciated.

Best regards,

Matt

Hi, Matt

The error you came across is a pure security problem, hence I suggest you post your question in SQL Security Forum:

http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=92&SiteID=1

Good Luck!

Ming.

|||

I originally posted this message to the Database Access forum, as I was thinking it might be related more to the methods used to access the database, as opposed to a pure security issue, as there does not appear to be an issue when using Microsoft native tools. However, now I am not so sure.

I have been working with SAP tech support on this issue, and this is what we've come up with so far.

The essential difference between running the distributed query from the Management Studio vs from within the R/3 application is the way the R/3 kernel establishes its security context when connecting to the database. The R/3 kernel connects to SQL Server as the NT user SAPServiceSID, and then executes a "SETUSER 'sid'" statement to establish the security context for the 'sid' schema in the database. The 'sid' database user has much reduced permissions from the SAPServiceSID NT user -- it is not a member of the sysadmin fixed server role, for instance -- thus adding to the overall security of the installation.

Normally "mixed mode" authentication is disabled on an R/3 installation, so it is not possible to logon interactively as the sid user. However, we have enabled it so that this linked server interface works coming the other direction (and that part does work), so I was able to connect directly as the 'sid' user and confirm that it CAN use the Linked Server. However, there is something inherently different about interactively logging on as the user vs switching to the user's context with a SETUSER or EXECUTE AS statement.

I have seen posts in other forums discussing the use of distributed transactions and the EXECUTE AS context switch. The essential problem, however, is that from within ABAP we cannot execute SETUSER or EXECUTE AS without causing R/3 to crash. We also cannot modify the permissions given to the 'sid' database user (like making it a sysadmin) without causing the same disastrous result, although I'm not certain why this last should be the case. We have been experimenting with exporting our Native SQL statements into a Stored Procedure with the EXECUTE AS context set on the procedure, but it hasn't worked. We still get the 15274 error ("Security Context Not Trusted") when we call the SP from within ABAP.

Regards,

Matt

|||

SETUSER cannot interact with linked servers and in SQL Server 2005 is marked as deprecated. In SQL Server 2005 we introduced a new EXECUTE AS and it has two different scopes: database or server.

The database scoped model is accessed via EXECUTE AS USER or by using the EXECUTE AS clause in a DB-scoped module (i.e. a SP, function, etc.). Because this model is permission based, by default the impersonated context is bound to the database where the impersonation took place, making this context invalid when you try to access other databases or when trying to access server resources (such as linked server information).

The server scoped model is accessed via EXECUTE AS LOGIN or by using EXECUTE AS on server scoped modules (server scoped DDL triggers). This impersonation is implicitly by the server, therefore the impersonated context is valid to access any database and server resources.

My guess is that you are using one of the database-scoped EXECUTE AS features and that’s why you are hitting this problem, can you please verify if this is correct, and in that case try using EXECUTE AS LOGIN instead? It should work with linked servers as long as long as the impersonated context is not a Windows account.

Please, let us know if this information was useful.

Thanks a lot,

-Raul Garcia

SDE/T

SQL Server Engine

|||

Raul,

Thanks for this clarification. This is helpful, although it doesn't solve the problem. So, apparently we cannot define a Stored Procedure with a server-scoped execution context (CREATE PROC xxx WITH EXECUTE AS LOGIN = 'login' is apparently not legitimate). However it does seem that we can insert an EXECUTE AS LOGIN = 'login' statement within the body of the SP.

Nevetheless, either way, the stored procedure works fine when executed from a Management Studio query window. It does not work when called from the R/3 application.

So, to recap, the R/3 application connects to the database first as a Windows user (SAPServiceD02), and then behind the scenes (transparent to the user and any programs we might write within R/3) it executes a SETUSER 'd02' statement. d02 is a SQL login, and all the user tables are in the d02 schema in the D02 database. This behavior is built into the R/3 kernel and we cannot change that. Although we are running on SQL Server 2005, the application is built to run on either 2005 or 2000.

From SQL tools such as Management Studio, both d02 and SAPServiceD02 can access the linked server. Both have a login mapping defined to a SQL login on the remote server. Likewise, using a Stored Procedure saved in the d02 schema with EXECUTE AS 'linkadm' (linkadm is a SQL user mapped to the dbo schema in both the D02 and master databases, a member of sysadmin, and also mapped in the Linked Server to the remote user), both d02 and SAPServiceD02, and indeed other sysadmin users, can access the Linked Server when executing the SP from Management Studio.

When calling the SP from within the R/3 application, however, which is using the same security credentials as just described, but has that implicit SETUSER 'd02' context, calling the SP doesn't get around the fact that we can't access the Linked Server. We still get the 15274 error, just like when we tried to call the Linked Server directly from within R/3. All of this worked very well when the DBMS was SQL 2000 and the schema was dbo. After upgrading to 2005 and migrating to the d02 schema, our troubles began. The essential problem appears to be the combination of Windows Authentication, schema-based installation with the schema based on a non-Windows, non-sysadmin SQL login name, and distributed transactions.

I think at this point (GoLive is just a few days away, and this is a potential showstopper) we must find some completely different way of executing these distributed transactions, and then hope that in the future there will be a fix, whether from Microsoft or SAP I don't know, that will allow us to revert to a more robust and integrated method. Meanwhile, the users will just have to ignore the man behind the curtain pulling the strings to make this work.

Best regards,

Matt

|||

You mentioned updating the R/3 application. Was it performing a SETUSER in the previous version as well?

Thanks
Laurentiu

|||

Laurentiu,

No, I don't believe it was, unless you had an MCOD (Multiple Components One Database) installation, which was not usual. In prior releases the standard installation had all the user tables in the dbo schema. With the most recent releases, however, SAP is moving towards schema-based installations. I believe this might be for multiple reasons, including supporting having multiple applications running in a single database, but also to increase security by having the connections be made using a schema user that normally cannot be interactively logged on (by default, an R/3 installation uses Windows Authentication only, so SQL logins are disabled), and that does not have to be a member of sysadmin. However, I cannot be certain what all the reasons for the switch may be.

Regards,

Matt

|||

SETUSER will not work with linked servers. This has been the case in SQL Server 2000 as well, so this issue appears to be hit because the R/3 application changed to perform a SETUSER. I believe that if it would have used an EXECUTE AS LOGIN instead, the issue would have been avoided, but with SETUSER, you are bound to get the 15274 error.

I suggest you contact the vendor of the R/3 application to get further help on this.

Thanks
Laurentiu

|||

Yes, we had been working with SAP (the vendor) from the beginning to resolve this issue, and although they were working diligently with us, a resolution did not look to be forthcoming before our GoLive deadline. In fact, I believe they escalated the issue to Microsoft themselves. Nevertheless, I posted here hoping against hope for something that might help us out.

However, we have now resolved the issue, although in a roundabout way, and not one that will work in a wide array of customer scenarios. The solution depended upon the fact that the remote server, being still on SQL Server 2000, did not have as many restrictions placed upon it with regard to the use of Linked Servers -- at least, the Linked Server connection from the remote system back to SAP continued to work just fine, despite SAP having been upgraded to SQL 2005. Additionally, SAP does provide a native capability to create a client-based connection to remote databases from within their application. It doesn't use Linked Servers, but rather opens up a SQLNCLI-based connection from the SAP server to the remote server, and allows the developer to execute Native SQL code against the remote database. This capability is referred to as DBCON with SAP. The limitation on DBCON, unfortunately, is that when working within this connection, the context is entirely that of the remote database, so access to local (SAP) tables is not available while in that context.

However, access to the Linked Server defined on the remote system is available.

So, we are able to perform distributed transactions between the two systems by executing them in the context of the remote system, while still controlling that execution from the SAP system.

I thank everyone for their suggestions and assistance while we worked on this issue.

Best regards,

Matt

|||

We experienced similar problems using Linked Server in combination with user context switching at a customer's site, although no SAP was involved. The scenario was getting data from Win2k3 SQL 2005 (target) by switching a user context to a domain user on another Win2k3 SQL 2005 (source). Logging on directly to the target with the domain user and getting the was no problem, also getting data with a sysadmin user on the target server via linked server on the source server actually worked. The source database also had the trustworthy property set.

The problem only occurred when connecting to the source server, switching the user context with "execute as user ..." and trying to get data from the target via linked server, which produced a connection error. What finally solved the problems was setting the remote connection properties in the surface area config to both TCP/IP and named-pipes, since the target only had tcp-ip activated. In the current config both protocols are activated on source and target server and now everything seems to work. Maybe these additional bits of experience are helpful to those struggling with similar problems.

sql

Current Security Context Not Trusted When Using Linked Server From SAP

Hello,

I am experiencing a head-scratcher of a problem when trying to use a Linked Server connection to query a remote SQL Server database from our SAP R/3 system. We have had this working just fine for some time, but after migrating to new hardware and upgrading OS, DBMS, and R/3, now we are running into problems.

The target database is a named instance on SQL Server 2000 SP3, Windows 2000 Server. The original source R/3 system was also on SQL Server 2000 (SP4), Windows 2000 Server. I had been using a Linked Server defined via SQL Enterprise Manager (actually defined when the source was on SQL Server 7), which called an alias defined with the Client Network Utility that pointed to the remote named instance. This alias and Linked Server worked great for several years.

Now we have migrated our R/3 system onto new hardware, running Windows Server 2003 SP1 and SQL Server 2005 SP1. I redefined the Linked Server on the new SQL 2005 installation, this time avoiding the alias and referencing the remote named instance directly, and it tests out just fine using queries from SQL Management Studio. It also tests fine with OSQL called from the R/3 server console, both when logged on as the application service account with a trusted connection, and with a SQL login as the schema owner. From outside of the application, I cannot make it fail. It works perfectly.

That all changes when I try to use the Linked Server within an SAP custom program (ABAP), however. The program crashes with a database interface error. The database error code is 15274, and the error text is "Access to the remote server is denied because the current security context is not trusted."

I have set the "trustworthy" property on the R/3 database, I have ensured the service account is a member of the sysadmin SQL role, I've even made it a member of the local Administrators group on both source and target servers, and I've done the same with the SQL Server service account (it uses a domain account). I have configured the Distributed Transaction Coordinator on the source (Win2003) system per Microsoft KB 839279 (this fixed problems with remote queries coming the other way from the SQL2000 system), and I've upgraded the system stored procedures on the target (SQL2000) system according to MS KB 906954. I also tried making the schema user a member of the sysadmin role, but that was disastrous, resulting in an instant R/3 crash (don't try this in production!), so I set it back the way it was (default).

What's really strange is no matter how I try this from outside the R/3 system, it works perfectly, but from within R/3 it does not. A search of SAP Notes, SDN forums, SAPFANS, Microsoft's KnowledgeBase, and MSDN Forums has not yielded quite the same problem (although that did lead me to learning about the "trustworthy" database property).

Any insight someone could offer on this thorny problem would be most appreciated.

Best regards,

Matt

Hi, Matt

The error you came across is a pure security problem, hence I suggest you post your question in SQL Security Forum:

http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=92&SiteID=1

Good Luck!

Ming.

|||

I originally posted this message to the Database Access forum, as I was thinking it might be related more to the methods used to access the database, as opposed to a pure security issue, as there does not appear to be an issue when using Microsoft native tools. However, now I am not so sure.

I have been working with SAP tech support on this issue, and this is what we've come up with so far.

The essential difference between running the distributed query from the Management Studio vs from within the R/3 application is the way the R/3 kernel establishes its security context when connecting to the database. The R/3 kernel connects to SQL Server as the NT user SAPServiceSID, and then executes a "SETUSER 'sid'" statement to establish the security context for the 'sid' schema in the database. The 'sid' database user has much reduced permissions from the SAPServiceSID NT user -- it is not a member of the sysadmin fixed server role, for instance -- thus adding to the overall security of the installation.

Normally "mixed mode" authentication is disabled on an R/3 installation, so it is not possible to logon interactively as the sid user. However, we have enabled it so that this linked server interface works coming the other direction (and that part does work), so I was able to connect directly as the 'sid' user and confirm that it CAN use the Linked Server. However, there is something inherently different about interactively logging on as the user vs switching to the user's context with a SETUSER or EXECUTE AS statement.

I have seen posts in other forums discussing the use of distributed transactions and the EXECUTE AS context switch. The essential problem, however, is that from within ABAP we cannot execute SETUSER or EXECUTE AS without causing R/3 to crash. We also cannot modify the permissions given to the 'sid' database user (like making it a sysadmin) without causing the same disastrous result, although I'm not certain why this last should be the case. We have been experimenting with exporting our Native SQL statements into a Stored Procedure with the EXECUTE AS context set on the procedure, but it hasn't worked. We still get the 15274 error ("Security Context Not Trusted") when we call the SP from within ABAP.

Regards,

Matt

|||

SETUSER cannot interact with linked servers and in SQL Server 2005 is marked as deprecated. In SQL Server 2005 we introduced a new EXECUTE AS and it has two different scopes: database or server.

The database scoped model is accessed via EXECUTE AS USER or by using the EXECUTE AS clause in a DB-scoped module (i.e. a SP, function, etc.). Because this model is permission based, by default the impersonated context is bound to the database where the impersonation took place, making this context invalid when you try to access other databases or when trying to access server resources (such as linked server information).

The server scoped model is accessed via EXECUTE AS LOGIN or by using EXECUTE AS on server scoped modules (server scoped DDL triggers). This impersonation is implicitly by the server, therefore the impersonated context is valid to access any database and server resources.

My guess is that you are using one of the database-scoped EXECUTE AS features and that’s why you are hitting this problem, can you please verify if this is correct, and in that case try using EXECUTE AS LOGIN instead? It should work with linked servers as long as long as the impersonated context is not a Windows account.

Please, let us know if this information was useful.

Thanks a lot,

-Raul Garcia

SDE/T

SQL Server Engine

|||

Raul,

Thanks for this clarification. This is helpful, although it doesn't solve the problem. So, apparently we cannot define a Stored Procedure with a server-scoped execution context (CREATE PROC xxx WITH EXECUTE AS LOGIN = 'login' is apparently not legitimate). However it does seem that we can insert an EXECUTE AS LOGIN = 'login' statement within the body of the SP.

Nevetheless, either way, the stored procedure works fine when executed from a Management Studio query window. It does not work when called from the R/3 application.

So, to recap, the R/3 application connects to the database first as a Windows user (SAPServiceD02), and then behind the scenes (transparent to the user and any programs we might write within R/3) it executes a SETUSER 'd02' statement. d02 is a SQL login, and all the user tables are in the d02 schema in the D02 database. This behavior is built into the R/3 kernel and we cannot change that. Although we are running on SQL Server 2005, the application is built to run on either 2005 or 2000.

From SQL tools such as Management Studio, both d02 and SAPServiceD02 can access the linked server. Both have a login mapping defined to a SQL login on the remote server. Likewise, using a Stored Procedure saved in the d02 schema with EXECUTE AS 'linkadm' (linkadm is a SQL user mapped to the dbo schema in both the D02 and master databases, a member of sysadmin, and also mapped in the Linked Server to the remote user), both d02 and SAPServiceD02, and indeed other sysadmin users, can access the Linked Server when executing the SP from Management Studio.

When calling the SP from within the R/3 application, however, which is using the same security credentials as just described, but has that implicit SETUSER 'd02' context, calling the SP doesn't get around the fact that we can't access the Linked Server. We still get the 15274 error, just like when we tried to call the Linked Server directly from within R/3. All of this worked very well when the DBMS was SQL 2000 and the schema was dbo. After upgrading to 2005 and migrating to the d02 schema, our troubles began. The essential problem appears to be the combination of Windows Authentication, schema-based installation with the schema based on a non-Windows, non-sysadmin SQL login name, and distributed transactions.

I think at this point (GoLive is just a few days away, and this is a potential showstopper) we must find some completely different way of executing these distributed transactions, and then hope that in the future there will be a fix, whether from Microsoft or SAP I don't know, that will allow us to revert to a more robust and integrated method. Meanwhile, the users will just have to ignore the man behind the curtain pulling the strings to make this work.

Best regards,

Matt

|||

You mentioned updating the R/3 application. Was it performing a SETUSER in the previous version as well?

Thanks
Laurentiu

|||

Laurentiu,

No, I don't believe it was, unless you had an MCOD (Multiple Components One Database) installation, which was not usual. In prior releases the standard installation had all the user tables in the dbo schema. With the most recent releases, however, SAP is moving towards schema-based installations. I believe this might be for multiple reasons, including supporting having multiple applications running in a single database, but also to increase security by having the connections be made using a schema user that normally cannot be interactively logged on (by default, an R/3 installation uses Windows Authentication only, so SQL logins are disabled), and that does not have to be a member of sysadmin. However, I cannot be certain what all the reasons for the switch may be.

Regards,

Matt

|||

SETUSER will not work with linked servers. This has been the case in SQL Server 2000 as well, so this issue appears to be hit because the R/3 application changed to perform a SETUSER. I believe that if it would have used an EXECUTE AS LOGIN instead, the issue would have been avoided, but with SETUSER, you are bound to get the 15274 error.

I suggest you contact the vendor of the R/3 application to get further help on this.

Thanks
Laurentiu

|||

Yes, we had been working with SAP (the vendor) from the beginning to resolve this issue, and although they were working diligently with us, a resolution did not look to be forthcoming before our GoLive deadline. In fact, I believe they escalated the issue to Microsoft themselves. Nevertheless, I posted here hoping against hope for something that might help us out.

However, we have now resolved the issue, although in a roundabout way, and not one that will work in a wide array of customer scenarios. The solution depended upon the fact that the remote server, being still on SQL Server 2000, did not have as many restrictions placed upon it with regard to the use of Linked Servers -- at least, the Linked Server connection from the remote system back to SAP continued to work just fine, despite SAP having been upgraded to SQL 2005. Additionally, SAP does provide a native capability to create a client-based connection to remote databases from within their application. It doesn't use Linked Servers, but rather opens up a SQLNCLI-based connection from the SAP server to the remote server, and allows the developer to execute Native SQL code against the remote database. This capability is referred to as DBCON with SAP. The limitation on DBCON, unfortunately, is that when working within this connection, the context is entirely that of the remote database, so access to local (SAP) tables is not available while in that context.

However, access to the Linked Server defined on the remote system is available.

So, we are able to perform distributed transactions between the two systems by executing them in the context of the remote system, while still controlling that execution from the SAP system.

I thank everyone for their suggestions and assistance while we worked on this issue.

Best regards,

Matt

|||

We experienced similar problems using Linked Server in combination with user context switching at a customer's site, although no SAP was involved. The scenario was getting data from Win2k3 SQL 2005 (target) by switching a user context to a domain user on another Win2k3 SQL 2005 (source). Logging on directly to the target with the domain user and getting the was no problem, also getting data with a sysadmin user on the target server via linked server on the source server actually worked. The source database also had the trustworthy property set.

The problem only occurred when connecting to the source server, switching the user context with "execute as user ..." and trying to get data from the target via linked server, which produced a connection error. What finally solved the problems was setting the remote connection properties in the surface area config to both TCP/IP and named-pipes, since the target only had tcp-ip activated. In the current config both protocols are activated on source and target server and now everything seems to work. Maybe these additional bits of experience are helpful to those struggling with similar problems.

current security context is not trusted (cross db ownership chaini

I cannot seem to get cross database ownership chaining to work.
Here’s what I have so far:
? I have a user in DatabaseA who is only in the public database role.
? In DatabaseB, I have created a ‘MyUsers’ database role (owned by dbo
), and
a ‘MySchema’ schema (also owned by dbo). I have granted select, execute
on
MySchema to MyUsers.
? The user in DatabaseB is in public and MyUsers database roles, and uses
MySchema as the default schema.
? I have enabled the ‘cross db ownership chaining’ option in both data
bases,
and also at the instance level.
? In DatabaseB, I have compiled MySchema.MyStoredProc which selects data
from DatabaseA.
When the user executes DatabaseB.MySchema.MyStoredProc, this error is raised
:
SELECT permission denied on object 'TableA', database 'DatabaseA', schema
'dbo'.
When MyStoredProc is recompiled WITH EXECUTE AS SELF (or OWNER), this error
is raised:
Access to the remote server is denied because the current security context
is not trusted.
Here are the particulars:
? SQL 2005 - 9.00.1399.06 (Intel X86), Build 2600: Service Pack 2
? Both databases have Compatibility Level = SQL Server 2000, although I’
ve
changed both to 2005 and the error persists.
Also, when I look at the Database Properties (Options property page), the
‘Cross-database Ownership Chaining Enabled’ property says False, and is
disabled for editing, even though sp_configure shows the value as 1.
Thanks,
Sam Tai> When the user executes DatabaseB.MySchema.MyStoredProc, this error is
> raised:
> SELECT permission denied on object 'TableA', database 'DatabaseA', schema
> 'dbo'.
Check to ensure that both DatabaseA and DatabaseB are owned by the same
login (same authorization). Although the authorization on both the
DatabaseB.MySchema and DatabaseA.dbo schema is 'dbo', these will map to
different server principals if the database owners are different and break
the ownership chain.
Also, the user in DatabaseB will need a security context in DatabaseA, even
if no permissions are granted. You'll need to either add the user or enable
the guest user in that database.
Hope this helps.
Dan Guzman
SQL Server MVP
"Sam Tai" <Sam Tai@.discussions.microsoft.com> wrote in message
news:1D3296BF-1228-4603-B433-97CC8FC53CE6@.microsoft.com...
>I cannot seem to get cross database ownership chaining to work.
> Here’s what I have so far:
> ? I have a user in DatabaseA who is only in the public database role.
> ? In DatabaseB, I have created a ‘MyUsers’ database role (owned by d
bo),
> and
> a ‘MySchema’ schema (also owned by dbo). I have granted select, execu
te
> on
> MySchema to MyUsers.
> ? The user in DatabaseB is in public and MyUsers database roles, and use
s
> MySchema as the default schema.
> ? I have enabled the ‘cross db ownership chaining’ option in both
> databases,
> and also at the instance level.
> ? In DatabaseB, I have compiled MySchema.MyStoredProc which selects data
> from DatabaseA.
> When the user executes DatabaseB.MySchema.MyStoredProc, this error is
> raised:
> SELECT permission denied on object 'TableA', database 'DatabaseA', schema
> 'dbo'.
> When MyStoredProc is recompiled WITH EXECUTE AS SELF (or OWNER), this
> error
> is raised:
> Access to the remote server is denied because the current security context
> is not trusted.
> Here are the particulars:
> ? SQL 2005 - 9.00.1399.06 (Intel X86), Build 2600: Service Pack 2
> ? Both databases have Compatibility Level = SQL Server 2000, although I
ve
> changed both to 2005 and the error persists.
> Also, when I look at the Database Properties (Options property page), the
> ‘Cross-database Ownership Chaining Enabled’ property says False, and i
s
> disabled for editing, even though sp_configure shows the value as 1.
> Thanks,
> Sam Tai|||Sam Tai (Sam Tai@.discussions.microsoft.com) writes:
> I cannot seem to get cross database ownership chaining to work.
> Heres what I have so far:
> I have a user in DatabaseA who is only in the public database role.
> In DatabaseB, I have created a MyUsers database role (owned by dbo),
> and a MySchema schema (also owned by dbo). I have granted select,
> execute on MySchema to MyUsers .
> The user in DatabaseB is in public and MyUsers database roles, and uses
> MySchema as the default schema.
> I have enabled the cross db ownership chaining option in both
> databases, and also at the instance level.
> In DatabaseB, I have compiled MySchema.MyStoredProc which selects data
> from DatabaseA.
You seem to be missing one thing: you need to do
ALTER DATABASE db SET DB_CHAINING ON
in both databases.

> When MyStoredProc is recompiled WITH EXECUTE AS SELF (or OWNER), this
> error is raised: Access to the remote server is denied because the
> current security context is not trusted.
This is because EXECUTE AS sets a database-user context, and you are
sandboxed into the current database. You make this, you need to set
the database as trustworthy. You also need to deal with certificates.
I have this in more detail on my web site in this article:
http://www.sommarskog.se/grantperm.html

> Here are the particulars:
> SQL 2005 - 9.00.1399.06 (Intel X86), Build 2600: Service Pack 2
Oh-oh, that is SQL 2005 RTM. I would recommend that you install SP2. To
make things a little more complicated there are some seroius bugs with
maintenance plans in SP2 as it was released, so make sure that you have
at least version 9.00.3054 when you are done. (The "Service Pack 2" in
the string relates to Windows.)
I should emphasize that this is not related to your issue, just a general
piece of advice.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Current Row Number

Hi,
Is there a way to get the current Row number.
If get this as a result of select statement,
12 as
56 yu
89 gh
I need like this
1 12 as
2 56 yu
3 89 gh
I saw some eg.s using temporary tables. But Is there a straight forward way
to get this.
Thanks
KiranYou can use Group By, Order By clauses to get the row number. or you can
also make sure of subquery to get the row number..check examples here
http://www.aspfaq.com/show.asp?id=2427
instead of temp tables, you can make use of table variables in the example
provided in the above link.
Av.
http://dotnetjunkies.com/WebLog/avnrao
http://www28.brinkster.com/avdotnet
"Kiran" <Kiran@.nospam.net> wrote in message
news:#0zmneS$EHA.2112@.TK2MSFTNGP14.phx.gbl...
> Hi,
> Is there a way to get the current Row number.
> If get this as a result of select statement,
> 12 as
> 56 yu
> 89 gh
> I need like this
> 1 12 as
> 2 56 yu
> 3 89 gh
> I saw some eg.s using temporary tables. But Is there a straight forward
way
> to get this.
> Thanks
> Kiran
>|||Kiran wrote:
> Hi,
> Is there a way to get the current Row number.
> If get this as a result of select statement,
> 12 as
> 56 yu
> 89 gh
> I need like this
> 1 12 as
> 2 56 yu
> 3 89 gh
> I saw some eg.s using temporary tables. But Is there a straight
> forward way to get this.
> Thanks
> Kiran
This uses a temp table as well, but maybe it's something different than
what you saw. Can you tell us how you are going to to know the order of
the rows during the select? Do you have an ORDER BY for the statement
that is driving the final order of the rows?
create table #OrderTest(col1 int not null, col2 varchar(3) not null)
insert into #OrderTest (col1, col2) values (10, 'AA')
insert into #OrderTest (col1, col2) values (12, 'AA')
insert into #OrderTest (col1, col2) values (13, 'AA')
insert into #OrderTest (col1, col2) values (16, 'AA')
Select IDENTITY(int, 1, 1) as "OrderCol", col1, col2
INTO #OrderTest2
From #OrderTest
Select * from #OrderTest2
Drop Table #OrderTest
Drop Table #OrderTest2
David Gugick
Imceda Software
www.imceda.com|||Hi Kiran,
Wait for SQL 2005
Regards,
Daniel
"Kiran" <Kiran@.nospam.net> wrote in message
news:#0zmneS$EHA.2112@.TK2MSFTNGP14.phx.gbl...
> Hi,
> Is there a way to get the current Row number.
> If get this as a result of select statement,
> 12 as
> 56 yu
> 89 gh
> I need like this
> 1 12 as
> 2 56 yu
> 3 89 gh
> I saw some eg.s using temporary tables. But Is there a straight forward
way
> to get this.
> Thanks
> Kiran
>

Current Row Number

Hi,
Is there a way to get the current Row number.
If get this as a result of select statement,
12 as
56 yu
89 gh
I need like this
1 12 as
2 56 yu
3 89 gh
I saw some eg.s using temporary tables. But Is there a straight forward way
to get this.
Thanks
KiranYou can use Group By, Order By clauses to get the row number. or you can
also make sure of subquery to get the row number..check examples here
http://www.aspfaq.com/show.asp?id=2427
instead of temp tables, you can make use of table variables in the example
provided in the above link.
--
Av.
http://dotnetjunkies.com/WebLog/avnrao
http://www28.brinkster.com/avdotnet
"Kiran" <Kiran@.nospam.net> wrote in message
news:#0zmneS$EHA.2112@.TK2MSFTNGP14.phx.gbl...
> Hi,
> Is there a way to get the current Row number.
> If get this as a result of select statement,
> 12 as
> 56 yu
> 89 gh
> I need like this
> 1 12 as
> 2 56 yu
> 3 89 gh
> I saw some eg.s using temporary tables. But Is there a straight forward
way
> to get this.
> Thanks
> Kiran
>|||Kiran wrote:
> Hi,
> Is there a way to get the current Row number.
> If get this as a result of select statement,
> 12 as
> 56 yu
> 89 gh
> I need like this
> 1 12 as
> 2 56 yu
> 3 89 gh
> I saw some eg.s using temporary tables. But Is there a straight
> forward way to get this.
> Thanks
> Kiran
This uses a temp table as well, but maybe it's something different than
what you saw. Can you tell us how you are going to to know the order of
the rows during the select? Do you have an ORDER BY for the statement
that is driving the final order of the rows?
create table #OrderTest(col1 int not null, col2 varchar(3) not null)
insert into #OrderTest (col1, col2) values (10, 'AA')
insert into #OrderTest (col1, col2) values (12, 'AA')
insert into #OrderTest (col1, col2) values (13, 'AA')
insert into #OrderTest (col1, col2) values (16, 'AA')
Select IDENTITY(int, 1, 1) as "OrderCol", col1, col2
INTO #OrderTest2
From #OrderTest
Select * from #OrderTest2
Drop Table #OrderTest
Drop Table #OrderTest2
David Gugick
Imceda Software
www.imceda.com|||Hi Kiran,
Wait for SQL 2005
Regards,
Daniel
"Kiran" <Kiran@.nospam.net> wrote in message
news:#0zmneS$EHA.2112@.TK2MSFTNGP14.phx.gbl...
> Hi,
> Is there a way to get the current Row number.
> If get this as a result of select statement,
> 12 as
> 56 yu
> 89 gh
> I need like this
> 1 12 as
> 2 56 yu
> 3 89 gh
> I saw some eg.s using temporary tables. But Is there a straight forward
way
> to get this.
> Thanks
> Kiran
>sql

Current Row Number

Hi,
Is there a way to get the current Row number.
If get this as a result of select statement,
12 as
56 yu
89 gh
I need like this
1 12 as
2 56 yu
3 89 gh
I saw some eg.s using temporary tables. But Is there a straight forward way
to get this.
Thanks
Kiran
You can use Group By, Order By clauses to get the row number. or you can
also make sure of subquery to get the row number..check examples here
http://www.aspfaq.com/show.asp?id=2427
instead of temp tables, you can make use of table variables in the example
provided in the above link.
Av.
http://dotnetjunkies.com/WebLog/avnrao
http://www28.brinkster.com/avdotnet
"Kiran" <Kiran@.nospam.net> wrote in message
news:#0zmneS$EHA.2112@.TK2MSFTNGP14.phx.gbl...
> Hi,
> Is there a way to get the current Row number.
> If get this as a result of select statement,
> 12 as
> 56 yu
> 89 gh
> I need like this
> 1 12 as
> 2 56 yu
> 3 89 gh
> I saw some eg.s using temporary tables. But Is there a straight forward
way
> to get this.
> Thanks
> Kiran
>
|||Kiran wrote:
> Hi,
> Is there a way to get the current Row number.
> If get this as a result of select statement,
> 12 as
> 56 yu
> 89 gh
> I need like this
> 1 12 as
> 2 56 yu
> 3 89 gh
> I saw some eg.s using temporary tables. But Is there a straight
> forward way to get this.
> Thanks
> Kiran
This uses a temp table as well, but maybe it's something different than
what you saw. Can you tell us how you are going to to know the order of
the rows during the select? Do you have an ORDER BY for the statement
that is driving the final order of the rows?
create table #OrderTest(col1 int not null, col2 varchar(3) not null)
insert into #OrderTest (col1, col2) values (10, 'AA')
insert into #OrderTest (col1, col2) values (12, 'AA')
insert into #OrderTest (col1, col2) values (13, 'AA')
insert into #OrderTest (col1, col2) values (16, 'AA')
Select IDENTITY(int, 1, 1) as "OrderCol", col1, col2
INTO #OrderTest2
From #OrderTest
Select * from #OrderTest2
Drop Table #OrderTest
Drop Table #OrderTest2
David Gugick
Imceda Software
www.imceda.com
|||Hi Kiran,
Wait for SQL 2005
Regards,
Daniel
"Kiran" <Kiran@.nospam.net> wrote in message
news:#0zmneS$EHA.2112@.TK2MSFTNGP14.phx.gbl...
> Hi,
> Is there a way to get the current Row number.
> If get this as a result of select statement,
> 12 as
> 56 yu
> 89 gh
> I need like this
> 1 12 as
> 2 56 yu
> 3 89 gh
> I saw some eg.s using temporary tables. But Is there a straight forward
way
> to get this.
> Thanks
> Kiran
>