473,721 Members | 4,008 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passthrough queries and RecordsAffected

Bri
Greetings,

I have a Passthrough Query to SQL Server that I want to know the
RecordsAffected , but it always returns 0. This worked perfectly when it
was an Access Query on the ODBC linked tables, but the query performed
so poorly that I converted it to a Passthrough. Now it runs in a
fraction of a second, but I no longer know how many records were inserted.

Thanks for any insights or solutions

--
Bri
Nov 13 '05 #1
7 10695
On Wed, 26 Jan 2005 23:20:48 GMT, Bri <no*@here.com > wrote:
Greetings,

I have a Passthrough Query to SQL Server that I want to know the
RecordsAffecte d, but it always returns 0. This worked perfectly when it
was an Access Query on the ODBC linked tables, but the query performed
so poorly that I converted it to a Passthrough. Now it runs in a
fraction of a second, but I no longer know how many records were inserted.

Thanks for any insights or solutions


If you're using ADO, just have your stored procedure return the number of
records affected through an output parameter, and use the Parameters
collection of the Command object to retrieve the value. If you're useing DAO,
have your stored procedure return the count of rows affected using a select
statement, and use the OpenRecordset method of the Querydef object to retrieve
the recordset with the count contained in the first row/field.

Nov 13 '05 #2
Bri


Steve Jorgensen wrote:
On Wed, 26 Jan 2005 23:20:48 GMT, Bri <no*@here.com > wrote:

Greetings,

I have a Passthrough Query to SQL Server that I want to know the
RecordsAffect ed, but it always returns 0. This worked perfectly when it
was an Access Query on the ODBC linked tables, but the query performed
so poorly that I converted it to a Passthrough. Now it runs in a
fraction of a second, but I no longer know how many records were inserted.

Thanks for any insights or solutions

If you're using ADO, just have your stored procedure return the number of
records affected through an output parameter, and use the Parameters
collection of the Command object to retrieve the value. If you're useing DAO,
have your stored procedure return the count of rows affected using a select
statement, and use the OpenRecordset method of the Querydef object to retrieve
the recordset with the count contained in the first row/field.


Steve,

I'm using DAO.

So you're saying I need to run a second query to collect the count of
the records inserted? This doesn't seem to be as efficient as the
RecordsAffected property. So, DAO won't return any messages or things
like @@RowCount? Rats. I had hoped to not have to do it that way. :(

Bri
Nov 13 '05 #3
On Thu, 27 Jan 2005 00:01:50 GMT, Bri <no*@here.com > wrote:


Steve Jorgensen wrote:
On Wed, 26 Jan 2005 23:20:48 GMT, Bri <no*@here.com > wrote:

Greetings,

I have a Passthrough Query to SQL Server that I want to know the
RecordsAffec ted, but it always returns 0. This worked perfectly when it
was an Access Query on the ODBC linked tables, but the query performed
so poorly that I converted it to a Passthrough. Now it runs in a
fraction of a second, but I no longer know how many records were inserted.

Thanks for any insights or solutions

If you're using ADO, just have your stored procedure return the number of
records affected through an output parameter, and use the Parameters
collection of the Command object to retrieve the value. If you're useing DAO,
have your stored procedure return the count of rows affected using a select
statement, and use the OpenRecordset method of the Querydef object to retrieve
the recordset with the count contained in the first row/field.


Steve,

I'm using DAO.

So you're saying I need to run a second query to collect the count of
the records inserted? This doesn't seem to be as efficient as the
RecordsAffecte d property. So, DAO won't return any messages or things
like @@RowCount? Rats. I had hoped to not have to do it that way. :(

Bri


You're not running a separate query to collect the count, you're just running
a second select statement to -return- the count, so DAO can read it. It's not
that inefficient.

CREATE PROCEDURE ...

<your query here>

SELECT @@ROWCOUNT AS ROWCOUNT
Nov 13 '05 #4
Bri
>>Steve,

I'm using DAO.

So you're saying I need to run a second query to collect the count of
the records inserted? This doesn't seem to be as efficient as the
RecordsAffect ed property. So, DAO won't return any messages or things
like @@RowCount? Rats. I had hoped to not have to do it that way. :(

Bri

You're not running a separate query to collect the count, you're just running
a second select statement to -return- the count, so DAO can read it. It's not
that inefficient.

CREATE PROCEDURE ...

<your query here>

SELECT @@ROWCOUNT AS ROWCOUNT


Steve,

OK, tried that and several variations on it and it didn't work for me.

Access seems to only see the first query as the error says that there
were no records returned.

To restate things; I have a Passthrough Query with the Returns Records
Property set to No. I then run in VBA:

Dim stSQL as String, qd as DAO.QueryDef, db as DAO.Database
Set DB=CurrenttDB()
stSQL = "INSERT ...." 'my actual sql is working so I don't think it is
relevent to the problem
Set qd = db.QueryDefs("q ryTempPassthrou ghAction")
qd.SQL = stSQL
qd.Execute dbFailOnError + dbSeeChanges
MsgBox "Signed out " & qd.RecordsAffec ted & " Items", vbInformation

The Message always says 'Signed out 0 Items' but all of the required
records were Inserted correctly.

Then I searched the Newsgroups and found nothing so I posted my question.

Based on your response I modified the Passthrough query (that now has
the SQL from the last succesful run) in several different versions of
the SQL, I also set the Returns Records property to Yes:

First Try
=========
INSERT ....
SELECT @@RowCount as RowCount

- Result: Error about RowCount being reserved word

Second Try
==========
INSERT ....
SELECT @@RowCount as MyRowCount

- Result: Pass-Through query with ReturnRecords property set to True did
not return any records.

Third Try
=========
CREATE PROCEDURE tmp AS
INSERT ....
SELECT @@RowCount as MyRowCount

- Result: Pass-Through query with ReturnRecords property set to True did
not return any records.

Forth Try
=========
Errors with Procedure tmp already exists

Am I missing something here? Can you give me any additional pointers?

--
Bri

Nov 13 '05 #5
On Thu, 27 Jan 2005 00:54:45 GMT, Bri <no*@here.com > wrote:
>>Steve,

I'm using DAO.

So you're saying I need to run a second query to collect the count of
the records inserted? This doesn't seem to be as efficient as the
RecordsAffec ted property. So, DAO won't return any messages or things
like @@RowCount? Rats. I had hoped to not have to do it that way. :(

Bri

You're not running a separate query to collect the count, you're just running
a second select statement to -return- the count, so DAO can read it. It's not
that inefficient.

CREATE PROCEDURE ...

<your query here>

SELECT @@ROWCOUNT AS ROWCOUNT


Steve,

OK, tried that and several variations on it and it didn't work for me.

Access seems to only see the first query as the error says that there
were no records returned.


Any stored procedure to be executed via ADO or DAO that executes more than one
statement should begin with SET NOCOUNT ON. Otherwise, all sorts of problems
occur including failing to retrieve the recordset from the final SELECT and
failing to get accurate error information in the Errors collection. Sorry - I
should have included that in my example.
Nov 13 '05 #6
Bri

Steve Jorgensen wrote:
On Thu, 27 Jan 2005 00:54:45 GMT, Bri <no*@here.com > wrote: <snip> Any stored procedure to be executed via ADO or DAO that executes more than one
statement should begin with SET NOCOUNT ON. Otherwise, all sorts of problems
occur including failing to retrieve the recordset from the final SELECT and
failing to get accurate error information in the Errors collection. Sorry - I
should have included that in my example.


Yahoo! That worked. I had one small thing that I'll mention for the
benefit of anyone else lurking, the Passthrough would revert to
ReturnsRecords= False when I set the SQL property, so I had to set it to
True before setting the recordset. Other than that it worked fine.

Since I am now setting a Recordset rather than Executing the query, will
I get any error messages if there is an error (ie. of the sort that
dbFailOnError gives when the Execute fails) and will an error backout
the whole batch if it is the second statement that fails?

Most of my experience with Acess to SQL has been with linked tables and
I've been dipping into Passthrough Queries (and Views and SPs) only when
I need to get better performance. The SQL Help isn't much help for this
and the SQL Server Online Books is a good reference, but not a good
learning from scratch source. Is there a website where I can learn more
about driving SQL Server from Access?

Thanks.
--
Bri

Nov 13 '05 #7
On Thu, 27 Jan 2005 03:00:47 GMT, Bri <no*@here.com > wrote:

Steve Jorgensen wrote:
On Thu, 27 Jan 2005 00:54:45 GMT, Bri <no*@here.com > wrote:<snip>
Any stored procedure to be executed via ADO or DAO that executes more than one
statement should begin with SET NOCOUNT ON. Otherwise, all sorts of problems
occur including failing to retrieve the recordset from the final SELECT and
failing to get accurate error information in the Errors collection. Sorry - I
should have included that in my example.


Yahoo! That worked. I had one small thing that I'll mention for the
benefit of anyone else lurking, the Passthrough would revert to
ReturnsRecords =False when I set the SQL property, so I had to set it to
True before setting the recordset. Other than that it worked fine.

Since I am now setting a Recordset rather than Executing the query, will
I get any error messages if there is an error (ie. of the sort that
dbFailOnErro r gives when the Execute fails) and will an error backout
the whole batch if it is the second statement that fails?


Yes, you will get the error. Rollback is controlled by the SQL Server logic,
not Access. In general, the statement within the stored procedure that had
the error will be rolled back automatically, but not any preceding statements.
You'll have to include BEGIN TRANSACTION and COMMIT TRANSACTION statements,
and error trapping with ROLLBACK TRANSACTION and RETURN if you want full,
multi-statment roll-back. Note that in T-SQL, there's nothing like ON ERROR
GOTO, so unfortunately, you need several lines of error handling code after
each logical statement.

Most of my experience with Acess to SQL has been with linked tables and
I've been dipping into Passthrough Queries (and Views and SPs) only when
I need to get better performance. The SQL Help isn't much help for this
and the SQL Server Online Books is a good reference, but not a good
learning from scratch source. Is there a website where I can learn more
about driving SQL Server from Access?

Thanks.


Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1430
by: Ron_A | last post by:
NewBee, Got some clues from some databases written using passthrough queries but don't understanc the case... statements. Is there any books anywhere that wiill include help on the syntax required for passthrough queries? Would I look for TSQL manuals???
1
1589
by: hromberg | last post by:
I have a set of passthrough queries that rely on a temporary table in SQL and currently I am dealing with this by creating a passthrough that builds the table and leaves the connection open for an extended period of time. However, rather than doing this I would like to open a connection at the onset of opening the Access app and closing it when done. My problem is: how do I create the open connection and use it in all other passthrough...
2
3724
by: Jack | last post by:
It appears that RecordsAffected reports the wrong value when a Null integer or date value is inserted using empty quotes. The insert works fine, but RecordsAffected reports 0 instead of 1. Here is the code... -------- Dim dbMyData As Database Dim strSQL As String
35
2546
by: NickName | last post by:
I understand it's easy to list all saved queries of a given Access database via Msysobjects system table. However, I have not seen any posting over this NG or other similar ones that also include SQL statement(content) of these queries, though I've noticed some VB code for that. Is that because it's simply impossible to get a query content (not query resultset) from a SQL stmt? Thanks in advance.
1
2274
by: KayC | last post by:
Hi I use Access2002 I have created a simple form with 3 parameter UserID, Password & Database When a user enters values into these text boxes a passthrough query to a Sybase database is envoked with the connection string set to the form parameters My problem is that when an invalid username, password or database string is entered the passthrough query still works even though looking at the connect property this has changed to the form...
2
12813
by: TjS | last post by:
Hellow, i am quite new to access, but i am searching for a visual basic script to change the connection string for all the passthrough queries which are in my access database. These passthrough queries have an ODBC datasource to an oracle database. I have about 80 passthrough queries, so i do not want to change one by one, therefor i need the script. Thanks in advance for your reactions...
6
5482
by: kentdahlgren | last post by:
Hi, I have a rather advanced MS Access 2002 solution where I use the RecordsAffected property of the Execute method for a Querydef. I’m using it all over the solution and it has worked as expected for years. Suddenly it does not in parts of the code, since it returns zero even when it should not. In the example below the record is there in table as it should after the execute and I expect RecordsAffected to be one. It is zero. Can anyone...
2
3616
by: RoadrunnerII | last post by:
Hi All I am new to this forum and still learning MS Access. Hoping this is the right place to ask If not please let me know! Looking for some help with the SQL statements in Access 2003 with the tables backended into MS SQL Server 2005 The queries work fine but cause the forms to be quite slow if I leave them as is. If I convert the Queries into Passthrough queries as suggested by a DBA I cannot get the Dlookup below to work The error I get...
3
2800
by: lukethegooner | last post by:
My quesion is, can I use a look up, of sorts, in an SQL Pass Through query? My problem is I have built an application that uses pass through queires to retrieve information from an Oracle source DB; rather than build long SQL statements I have several simple pass through's that I use to populate local tables then run the queries off those tables... A typical and simplified SQL might be like ...
0
9373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9227
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6676
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4761
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3206
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2590
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2143
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.