Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > SET NOCOUNT ON?

Reply
Thread Tools

SET NOCOUNT ON?

 
 
Rob Meade
Guest
Posts: n/a
 
      06-17-2006
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


 
Reply With Quote
 
 
 
 
Rob Meade
Guest
Posts: n/a
 
      06-17-2006
I don't understand...

What's the difference between these two...

objConnection99.Open "Provider=SQLOLEDB;Data Source=TITUS;User
ID=<user.;Password=<password>;Initial Catalog=<db>"

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

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;"...downside is having to setup the DSN on the sever...

What am I missing?

Regards

Rob


 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      06-18-2006
Rob Meade wrote:
> I don't understand...
>
> What's the difference between these two...
>
> objConnection99.Open "Provider=SQLOLEDB;Data Source=TITUS;User
> ID=<user.;Password=<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=<password>"


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;"...downside 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"


 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      06-18-2006
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"


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Treeview questions - how to set set start node and how to catch click event Alan Silver ASP .Net 0 12-21-2005 10:40 AM
Re: SET NOCOUNT ON OPTION Cirrosi ASP .Net 0 10-21-2004 08:12 PM
Re: SET NOCOUNT ON OPTION Kikoz ASP .Net 1 10-20-2004 02:14 PM
java.lang.Set with elements of type java.lang.Set Harald Kirsch Java 4 08-31-2004 10:40 AM
Unable to set focus to textfield in a applet if browser is set to Sun JRE 1.4 Manav Java 0 10-15-2003 03:42 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57