Showing posts with label executes. Show all posts
Showing posts with label executes. Show all posts

Tuesday, March 20, 2012

Access.adp & Stored Procedures

Here is a bug - maybe.
I have an access.adp that executes a sproc on SQL Server 2000. The sproc
contains a correlated subquery that updates the table ExcelData. Works fine
until someone other than the dbo uses the project. The sproc will not update
a table owned by any non-dbo user. The sproc does not use any owner name so
it should work for any user and update the table they own. However the sproc
will only update the table dbo.ExcelData and that only when it is executed b
y
a dbo - which is right.
Curiously, I copied the SQL statement from the sproc into an Access VBA
module in the project. Changed it into a string and executed it using a
command object. Works perfectly. Will correctly update the table owned y the
user whether the user is the dbo or not.
I'd rather have one sproc on the server than the sql statement in the VBA
module because, actually, the sproc involves about 30 updating queries, not
just one and I'd like to minimize network trafic.
And I do not want a sproc for each potential user even though that would
allow each sproc to identify the table by the owner's name.
Question: How can a sproc be tweaked to recognize the current user when the
user is not the dbo and update the correct table when the sproc is executed
from an ADP?
--
malcolmIt's hard to say from your description what's going on, but I suspect
it's a naming issue rather than a permissions one since you can run
VBA code to achieve the desired result. One way to verify this is to
put a Profiler trace on the app and see what the exact calls are.
Another is to always use the two-part name, either dbo.Tablename or
ownername.Tablename, depending. Unlike Access, SQL Server considers
the name of the object to be the two part owner.object name, so if the
object was created by a symin it will be owned by dbo. If it was
created by a non-symin, it will be owned by that person. So you can
have a dbo.Table1, a Fred.Table1, a Cindy.Table1, (etc etc etc) all in
the same database, and each one will need its own sets of permissions
granted to other users. If Access sends a query across the wire for
"Table1", which one would you expect SQLS to use? So in order to avoid
future anguish, have everything owned by dbo, and specify the two-part
name everywhere, in the UI and in your code. And use Profiler to see
what's actually going across the wire. See SQL Books Online, "Using
Ownership Chains" for more information.
--Mary
On Sat, 27 Aug 2005 15:58:02 -0700, "malcolm"
<ramartower@.access312.com> wrote:

>Here is a bug - maybe.
>I have an access.adp that executes a sproc on SQL Server 2000. The sproc
>contains a correlated subquery that updates the table ExcelData. Works fine
>until someone other than the dbo uses the project. The sproc will not updat
e
>a table owned by any non-dbo user. The sproc does not use any owner name so
>it should work for any user and update the table they own. However the spro
c
>will only update the table dbo.ExcelData and that only when it is executed
by
>a dbo - which is right.
>Curiously, I copied the SQL statement from the sproc into an Access VBA
>module in the project. Changed it into a string and executed it using a
>command object. Works perfectly. Will correctly update the table owned y th
e
>user whether the user is the dbo or not.
>I'd rather have one sproc on the server than the sql statement in the VBA
>module because, actually, the sproc involves about 30 updating queries, not
>just one and I'd like to minimize network trafic.
>And I do not want a sproc for each potential user even though that would
>allow each sproc to identify the table by the owner's name.
>Question: How can a sproc be tweaked to recognize the current user when the
>user is not the dbo and update the correct table when the sproc is executed
>from an ADP?|||Hello, Malcolm

>From your description, I understand that:
1. You have some tables with the same name and same structure, owned by
different users (including dbo);
2. You wrote a stored procedure (owned by dbo), that accesses that
table(s), specifying only the name of the table (not the owner)
3. You want the procedure to access each user's table, when invoked by
non-dbo users.
4. Currently, the procedure always accesses the tables owned by dbo
(regardless of which user invoked it).
First, let me say that what you are seeing it's not a bug, it's the
expected behaviour. Normally, when an object is accessed without
specifying the owner name, SQL Server looks first for an object with
that name owned by the current user, and then (if it doesn't exist) it
looks for an object owned by dbo. However, in stored procedures, when
an object is accessed without specifying the owner name, SQL Server
only looks for an object owned by the owner of the stored procedure.
For more informations, see:
http://msdn.microsoft.com/library/e...curity_2sz6.asp
http://msdn.microsoft.com/library/e...des_07_786r.asp
If you want a procedure (owned by dbo) to access each user's table
(when invoked by non-dbo users), then you can use EXEC('...') in the
stored procedure, so the queries are considered in another batch,
outside the scope of the procedure.
For example (considering that you already have user "a" and user "b" in
your database):
CREATE TABLE a.TheTable (a int PRIMARY KEY)
CREATE TABLE b.TheTable (b int PRIMARY KEY)
CREATE TABLE dbo.TheTable (x int PRIMARY KEY)
GO
CREATE PROCEDURE dbo.Test
AS
EXEC ('SELECT * FROM TheTable')
SELECT * FROM TheTable
GO
GRANT EXEC ON dbo.Test TO public
The first statement in the procedure will select from the table owned
by the user that invoked the procedure, but the second statement will
select from the table owned by the user that owns this procedure (dbo).
Razvan

Friday, February 24, 2012

Access Pass through Query Executes Multiple Times

Hi,
I am using MSACCESS 2002 with SQL Server 2000. I have an unbound form when it opens I assign a pass through query to the rowsource of a combo box. The pass through query calls a stored procedure. On my form unload event I set the rowsource to empty.
When I load the form I am only assigning the query once, however, it is appearing in profiler as many as three times within milliseconds of each other.
Can someone tell me if the query is actually executing three times or is this some anomoly of profiler that is causing it to appear this way. I have included the results of the trace below.
Thanks
1.
EVENT CLASS TEXT DATA APPLICATION nAME LOGIN NAME
------
SQL:BatchCompletedexec setEECboRS '4/23/2004','4/29/2004'Microsoft Office XPScheduler15
READS WRITES CPU DURATION CLIENT PROCESS ID START TIME
-----
6330165712572004-04-24 23:45:05.953
2.
EVENT CLASS TEXT DATA APPLICATION nAME LOGIN NAME
------
SQL:BatchCompletedexec setEECboRS '4/23/2004','4/29/2004'Microsoft Office XPScheduler16
READS WRITES CPU DURATION CLIENT PROCESS ID START TIME
-----
6330135712572004-04-24 23:45:05.970
3.
EVENT CLASS TEXT DATA APPLICATION nAME LOGIN NAME
------
SQL:BatchCompletedexec setEECboRS '4/23/2004','4/29/2004'Microsoft Office XPScheduler16
READS WRITES CPU DURATION CLIENT PROCESS ID START TIME
-----
6330165712572004-04-24 23:45:05.983
Since you're using an unbound form, step through your code and then
look at the Profiler trace after each step. It's possible that this is
caused because you don't have SET NOCOUNT ON as the first line in your
stored procedure.
--Mary
On Sun, 25 Apr 2004 06:06:02 -0700, "Lance"
<anonymous@.discussions.microsoft.com> wrote:

>Hi,
>I am using MSACCESS 2002 with SQL Server 2000. I have an unbound form when it opens I assign a pass through query to the rowsource of a combo box. The pass through query calls a stored procedure. On my form unload event I set the rowsource to empty.
When I load the form I am only assigning the query once, however, it is appearing in profiler as many as three times within milliseconds of each other.
>Can someone tell me if the query is actually executing three times or is this some anomoly of profiler that is causing it to appear this way. I have included the results of the trace below.
>Thanks
>1.
> EVENT CLASS TEXT DATA APPLICATION nAME LOGIN NAME
>------
>SQL:BatchCompletedexec setEECboRS '4/23/2004','4/29/2004'Microsoft Office XPScheduler15
> READS WRITES CPU DURATION CLIENT PROCESS ID START TIME
>-----
>6330165712572004-04-24 23:45:05.953
>2.
> EVENT CLASS TEXT DATA APPLICATION nAME LOGIN NAME
>------
>SQL:BatchCompletedexec setEECboRS '4/23/2004','4/29/2004'Microsoft Office XPScheduler16
> READS WRITES CPU DURATION CLIENT PROCESS ID START TIME
>-----
>6330135712572004-04-24 23:45:05.970
>3.
> EVENT CLASS TEXT DATA APPLICATION nAME LOGIN NAME
>------
>SQL:BatchCompletedexec setEECboRS '4/23/2004','4/29/2004'Microsoft Office XPScheduler16
> READS WRITES CPU DURATION CLIENT PROCESS ID START TIME
>-----
>6330165712572004-04-24 23:45:05.983
|||Mary,
I did not have set nocount on but adding it did not affect the results in profiler. The profiler results I posted all have the same processID but one has a CPU value of 13 while the other two lines have a CPU value of 16. The computer I am using has an
intel pentium 4 hyperthreading cpu that appears as two CPU to my operating system. This may be what is causing the results to appear multiple times even though the stored procedure is only executed once. Can you confirm by looking at the output I posted
?
Thanks,
Lance
|||That I couldn't tell you -- can you test from a different machine?
--mary
On Wed, 28 Apr 2004 10:10:58 -0700, "Lance"
<anonymous@.discussions.microsoft.com> wrote:

>I did not have set nocount on but adding it did not affect the results in profiler. The profiler results I posted all have the same processID but one has a CPU value of 13 while the other two lines have a CPU value of 16. The computer I am using has an
intel pentium 4 hyperthreading cpu that appears as two CPU to my operating system. This may be what is causing the results to appear multiple times even though the stored procedure is only executed once. Can you confirm by looking at the output I poste
d?
|||Mary,
I can not move it to another machine at this time but will eventually (well, I could but don't want to for this as I don't have the time and it can wait). By the way, I do have a book that you co-wrote and found it a very good reference.
Lance
|||My form calls a pass-through query in my Access 2000/SQL Server App, and it actually executes the stored procedure 3 times. This is very annoying.
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
|||My form calls a pass-through query in my Access 2000/SQL Server App, and it actually executes the stored procedure 3 times. This is very annoying.
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
|||Open a Profiler trace and step through your form code that calls the
stored procedure to pinpoint why it's getting called 3 times.
--Mary
On Tue, 29 Jun 2004 13:33:46 -0700, SqlJunkies User
<User@.-NOSPAM-SqlJunkies.com> wrote:

>My form calls a pass-through query in my Access 2000/SQL Server App, and it actually executes the stored procedure 3 times. This is very annoying.
>--
>Posted using Wimdows.net NntpNews Component -
>Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.

Sunday, February 19, 2012

Access Pass through Query Executes Multiple Times

Hi,
I am using MSACCESS 2002 with SQL Server 2000. I have an unbound form when
it opens I assign a pass through query to the rowsource of a combo box. Th
e pass through query calls a stored procedure. On my form unload event I se
t the rowsource to empty.
When I load the form I am only assigning the query once, however, it is appe
aring in profiler as many as three times within milliseconds of each other.
Can someone tell me if the query is actually executing three times or is thi
s some anomoly of profiler that is causing it to appear this way. I have in
cluded the results of the trace below.
Thanks
1.
EVENT CLASS TEXT DATA
APPLICATION nAME LOGIN NAME
----
----
SQL:BatchCompleted exec setEECboRS '4/23/2004','4/29/2004' Microsoft Office
XP Scheduler 15
READS WRITES CPU DURATION CLIENT PROCESS ID START TIME
----
--
633 0 16 5712 57 2004-04-24 23:45:05.953
2.
EVENT CLASS TEXT DATA
APPLICATION nAME LOGIN NAME
----
----
SQL:BatchCompleted exec setEECboRS '4/23/2004','4/29/2004' Microsoft Office
XP Scheduler 16
READS WRITES CPU DURATION CLIENT PROCESS ID START TIME
----
--
633 0 13 5712 57 2004-04-24 23:45:05.970
3.
EVENT CLASS TEXT DATA
APPLICATION nAME LOGIN NAME
----
----
SQL:BatchCompleted exec setEECboRS '4/23/2004','4/29/2004' Microsoft Office
XP Scheduler 16
READS WRITES CPU DURATION CLIENT PROCESS ID START TIME
----
--
633 0 16 5712 57 2004-04-24 23:45:05.983Since you're using an unbound form, step through your code and then
look at the Profiler trace after each step. It's possible that this is
caused because you don't have SET NOCOUNT ON as the first line in your
stored procedure.
--Mary
On Sun, 25 Apr 2004 06:06:02 -0700, "Lance"
<anonymous@.discussions.microsoft.com> wrote:

>Hi,
>I am using MSACCESS 2002 with SQL Server 2000. I have an unbound form when it open
s I assign a pass through query to the rowsource of a combo box. The pass through
query calls a stored procedure. On my form unload event I set the rowsource to empt
y.
When I load the form I am only assigning the query once, however, it is appearing in profile
r as many as three times within milliseconds of each other.
>Can someone tell me if the query is actually executing three times or is th
is some anomoly of profiler that is causing it to appear this way. I have i
ncluded the results of the trace below.
>Thanks
>1.
> EVENT CLASS TEXT DATA
APPLICATION nAME LOGIN NAME
>----
---
>SQL:BatchCompleted exec setEECboRS '4/23/2004','4/29/2004' Microsoft Office
XP Scheduler 15
> READS WRITES CPU DURATION CLIENT PROCESS ID STAR
T TIME
>----
--
> 633 0 16 5712 57 2004-04-24 23:45:05.953
>2.
> EVENT CLASS TEXT DATA
APPLICATION nAME LOGIN NAME
>----
---
>SQL:BatchCompleted exec setEECboRS '4/23/2004','4/29/2004' Microsoft Office
XP Scheduler 16
> READS WRITES CPU DURATION CLIENT PROCESS ID STAR
T TIME
>----
--
> 633 0 13 5712 57 2004-04-24 23:45:05.970
>3.
> EVENT CLASS TEXT DATA
APPLICATION nAME LOGIN NAME
>----
---
>SQL:BatchCompleted exec setEECboRS '4/23/2004','4/29/2004' Microsoft Office
XP Scheduler 16
> READS WRITES CPU DURATION CLIENT PROCESS ID STAR
T TIME
>----
--
> 633 0 16 5712 57 2004-04-24 23:45:05.983|||Mary,
I did not have set nocount on but adding it did not affect the results in pr
ofiler. The profiler results I posted all have the same processID but one h
as a CPU value of 13 while the other two lines have a CPU value of 16. The
computer I am using has an
intel pentium 4 hyperthreading cpu that appears as two CPU to my operating s
ystem. This may be what is causing the results to appear multiple times eve
n though the stored procedure is only executed once. Can you confirm by loo
king at the output I posted
?
Thanks,
Lance|||That I couldn't tell you -- can you test from a different machine?
--mary
On Wed, 28 Apr 2004 10:10:58 -0700, "Lance"
<anonymous@.discussions.microsoft.com> wrote:

>I did not have set nocount on but adding it did not affect the results in profiler.
The profiler results I posted all have the same processID but one has a CPU value
of 13 while the other two lines have a CPU value of 16. The computer I am using has
an
intel pentium 4 hyperthreading cpu that appears as two CPU to my operating s
ystem. This may be what is causing the results to appear multiple times eve
n though the stored procedure is only executed once. Can you confirm by loo
king at the output I poste
d?|||Mary,
I can not move it to another machine at this time but will eventually (well,
I could but don't want to for this as I don't have the time and it can wait
). By the way, I do have a book that you co-wrote and found it a very good
reference.
Lance|||My form calls a pass-through query in my Access 2000/SQL Server App, and it
actually executes the stored procedure 3 times. This is very annoying.
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine sup
ports Post Alerts, Ratings, and Searching.|||Open a Profiler trace and step through your form code that calls the
stored procedure to pinpoint why it's getting called 3 times.
--Mary
On Tue, 29 Jun 2004 13:33:46 -0700, SqlJunkies User
<User@.-NOSPAM-SqlJunkies.com> wrote:

>My form calls a pass-through query in my Access 2000/SQL Server App, and it
actually executes the stored procedure 3 times. This is very annoying.
>--
>Posted using Wimdows.net NntpNews Component -
>Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine supports P
ost Alerts, Ratings, and Searching.