473,661 Members | 2,440 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SET NOCOUNT ON?

Hi all,

I'm trying to insert a record into a database via ASP, and then extract the
id of the current row using @@IDENTITY...

I've read the articles on ASPAQ and somewhere else regarding the use of the
above, but I do actually want the ID of the row inserted using this
connection, not just the most recent record if that makes any sense...

Now - what's frustrating me the most at the moment, is that when I execute
my stored procedure via my code ( the same code I use else where with no
problems ) - I do not get a value back for the @@IDENTITY in ASP (I do in
SQL if I run the SQL statement that I generated)..

The only way I seem to be able to get a response is to add "SET NOCOUNT ON;
" infront of my SQL statement - doing so gets me a value back - Hooray....

However, that cheer is short lived because for some bizarre reason - I now
get 4 rows inserted into the database each time i run it!?!

There is NO loop anyway near my inserting code..and if I take the SET
NOCOUNT ON; out of the statement it does infact run correctly and insert
just the one row and I'd expect but - no returned value...

Has anyone else come across this bizarre behaviour before?

I use this same process else where and my technique (good or bad) is the
same, I dont understand why its going wrong?!

Any help would be appreciated....

Regards

Rob
Jun 17 '06 #1
3 4956
I don't understand...

What's the difference between these two...

objConnection99 .Open "Provider=SQLOL EDB;Data Source=TITUS;Us er
ID=<user.;Passw ord=<password>; Initial Catalog=<db>"

objConnection99 .Open "DSN=<dsn>;uid= <user>;pwd=<pas sword>"

When I use the top one - I get the whole load of pain as described in my
first post..

When I use the second one I have no problems and dont need to specify "SET
NOCOUNT ON;"...downsid e is having to setup the DSN on the sever...

What am I missing?

Regards

Rob
Jun 17 '06 #2
Rob Meade wrote:
I don't understand...

What's the difference between these two...

objConnection99 .Open "Provider=SQLOL EDB;Data Source=TITUS;Us er
ID=<user.;Passw ord=<password>; Initial Catalog=<db>"

This uses the native OLE DB provider for SQL Server, and thus communicates
directly with the database rather than going through an extra layer of code.
objConnection99 .Open "DSN=<dsn>;uid= <user>;pwd=<pas sword>"
This uses the default OLE DB provider for ODBC databases (MSDASQL), so
communications with the database are using an extra layer of software (ODBC)

When I use the top one - I get the whole load of pain as described in
my first post..

When I use the second one I have no problems and dont need to specify
"SET NOCOUNT ON;"...downsid e is having to setup the DSN on the
sever...
What am I missing?

Hard to say without seeing the code.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jun 18 '06 #3
Rob Meade wrote:
Hi all,

I'm trying to insert a record into a database via ASP, and then
extract the id of the current row using @@IDENTITY...

I've read the articles on ASPAQ and somewhere else regarding the use
of the above, but I do actually want the ID of the row inserted using
this connection, not just the most recent record if that makes any
sense...
Now - what's frustrating me the most at the moment, is that when I
execute my stored procedure via my code ( the same code I use else
where with no problems ) - I do not get a value back for the
@@IDENTITY in ASP (I do in SQL if I run the SQL statement that I
generated)..
The only way I seem to be able to get a response is to add "SET
NOCOUNT ON; " infront of my SQL statement - doing so gets me a value
back - Hooray....
How is the procedure returning the value?
However, that cheer is short lived because for some bizarre reason -
I now get 4 rows inserted into the database each time i run it!?!

There is NO loop anyway near my inserting code..and if I take the SET
NOCOUNT ON; out of the statement it does infact run correctly and
insert just the one row and I'd expect but - no returned value...

Has anyone else come across this bizarre behaviour before?

I use this same process else where and my technique (good or bad) is
the same, I dont understand why its going wrong?!

Any help would be appreciated....


Show us how to reproduce this behavior. Give us a CREATE TABLE statement and
a CREATE PROCEDURE statement, and the vbscript code you use to run the
procedure.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jun 18 '06 #4

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

Similar topics

4
14239
by: Hank | last post by:
I have two SQL Server 2000 machines (server_A and server_B). I've used sp_addlinkedserver to link them both, the link seems to behave fine. I can execute remote queries and do all types of neat things from one while logged onto the other. I'm working on a project to keep the data in the two systems synchronized, so I'm using triggers on both sides to update each other. For testing, I've created a simple, one-column table on both...
3
3241
by: GM | last post by:
i use set nocount on inside the stored procedure at the beginning however the Number of Rows Counted/Affected shows up when I execute the stored procedure in query analyzer using execute sprocName. I also tried to add the SET NOCOUNT ON at the beginning of the procedure and it still shows the number of rows affected. if i set
42
11524
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
7
2535
by: Leon | last post by:
DOES SETTING NOCOUNT ON option affect my stored procedures and website performance in anyway within my asp.net application? When and when not to set SET NOCOUNT ON? I know what it does but not exactly where and when I want to use it. i.e. CREATE PROCEDURE GetAuthorization 2.0 @Username Varchar( 20 ),
1
11837
by: Lyle Fairfield | last post by:
MS-SQL 2000, Access 2003, ADO 2.8 Please, consider the SQL string in the following code: Dim r As ADODB.Recordset Dim r2 As ADODB.Recordset Set r = CurrentProject.Connection.Execute( _ "SET NOCOUNT ON " _ & "SELECT * FROM FFDBATransactions" _ & "; SET NOCOUNT ON " _
4
2454
by: jim_geissman | last post by:
There are four limitations or apparent bugs I have experienced in 2005 MS. Two I know are for real. Two real limitations/bugs -- 1. Can't edit table-valued function. 2. Can't get nulls to be missing (blank) in text output pane Two more I just encountered, and am wondering about --
3
1352
by: Patrick.O.Ige | last post by:
Hi guys, Is there any free stuff to generate DAL code out there? Thanks in advance
0
825
by: praveen1983 | last post by:
How to find set nocount is on or off in the stored procedures?
3
16915
by: anuragshrivastava64 | last post by:
Can anyone plz tell Set NoCount on equivalent in Oracle. I have used it only in SQL
0
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8855
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
8758
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...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7364
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
6185
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
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
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
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.