473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

how to deal with this SQLException

Hello,
I have written code in ASP.net 2.0 to insert the values in a SQL
Server Database. the code is as follows

Dim addemp As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand("INSERT INTO Department
(department_name,lastname,firstname,title,hiredate ,reportsto,photo)
values(@departmentname,@lastname,@firstname,@title ,@hiredate,@reportsto,0x0);"
& "SELECT @identity=SCOPE_IDENTITY();" & "SELECT @pointer=TEXTPTR(photo) from
department where department_id=@identity", con)

Now the SQLException is raised as :

'SCOPE_IDENTITY' is not a recognized function name.

I want to know if the syntax of the above statement is correct or not also
how to deal with this exception

Thank you

Nov 19 '05 #1
3 3009
This function is new in SQL Server 2000. Which version are you using ?

If 2000 or later try perhaps to test just the offending function callinc ase
it would be something else causing theis problem (missing variable
declarations ?)

--

"anoop" <an***@discussions.microsoft.com> a écrit dans le message de
news:E1**********************************@microsof t.com...
Hello,
I have written code in ASP.net 2.0 to insert the values in a SQL
Server Database. the code is as follows

Dim addemp As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand("INSERT INTO Department
(department_name,lastname,firstname,title,hiredate ,reportsto,photo)
values(@departmentname,@lastname,@firstname,@title ,@hiredate,@reportsto,0x0)
;" & "SELECT @identity=SCOPE_IDENTITY();" & "SELECT @pointer=TEXTPTR(photo) from department where department_id=@identity", con)

Now the SQLException is raised as :

'SCOPE_IDENTITY' is not a recognized function name.

I want to know if the syntax of the above statement is correct or not also
how to deal with this exception

Thank you


Nov 19 '05 #2
I'm not sure why you're getting the specific message you're getting.
However, from reading SQL Server Books Online, it looks to me like the SQL
Statements you are sending are not part of the same Stored Procedure, batch,
or function. Therefore, you should use @@IDENTITY instead, which is not
limited to statements in the same scope. Example:

SELECT @identity = @@IDENTITY;

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"anoop" <an***@discussions.microsoft.com> wrote in message
news:E1**********************************@microsof t.com...
Hello,
I have written code in ASP.net 2.0 to insert the values in a SQL
Server Database. the code is as follows

Dim addemp As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand("INSERT INTO Department
(department_name,lastname,firstname,title,hiredate ,reportsto,photo)
values(@departmentname,@lastname,@firstname,@title ,@hiredate,@reportsto,0x0);"
& "SELECT @identity=SCOPE_IDENTITY();" & "SELECT @pointer=TEXTPTR(photo)
from
department where department_id=@identity", con)

Now the SQLException is raised as :

'SCOPE_IDENTITY' is not a recognized function name.

I want to know if the syntax of the above statement is correct or not also
how to deal with this exception

Thank you


Nov 19 '05 #3
actually scope_identity() should be used instead of @@identity.

scope_identity() is the last identiy assigned in the current context (scope)
by the last statment
@@identity is the last identity assigned by the last statement
for example if table foo has a trigger that inserts into another identity
table foolog

insert foo (1)
select @id = @@identity -- @id is the the identity of the row inserted in
foolog

insert foo (2)
select @id = identity_scope() -- @id is the the identity of the row inserted
in foo
-- bruce (sqlwork.com)

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:eE**************@TK2MSFTNGP10.phx.gbl...
I'm not sure why you're getting the specific message you're getting.
However, from reading SQL Server Books Online, it looks to me like the SQL
Statements you are sending are not part of the same Stored Procedure,
batch, or function. Therefore, you should use @@IDENTITY instead, which is
not limited to statements in the same scope. Example:

SELECT @identity = @@IDENTITY;

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Ambiguity has a certain quality to it.

"anoop" <an***@discussions.microsoft.com> wrote in message
news:E1**********************************@microsof t.com...
Hello,
I have written code in ASP.net 2.0 to insert the values in a SQL
Server Database. the code is as follows

Dim addemp As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand("INSERT INTO Department
(department_name,lastname,firstname,title,hiredate ,reportsto,photo)
values(@departmentname,@lastname,@firstname,@title ,@hiredate,@reportsto,0x0);"
& "SELECT @identity=SCOPE_IDENTITY();" & "SELECT @pointer=TEXTPTR(photo)
from
department where department_id=@identity", con)

Now the SQLException is raised as :

'SCOPE_IDENTITY' is not a recognized function name.

I want to know if the syntax of the above statement is correct or not
also
how to deal with this exception

Thank you



Nov 19 '05 #4

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

Similar topics

0
by: Eckard Buchner | last post by:
Hi, we have a query that returns only a few rows, but has a lot of columns in group by clause. In some cases we receive an SQL Exception. Here is the trace setString (1, 20040928001) called...
1
by: ralamo | last post by:
INSERT INTO ECN_1 (Old_SbPartNo, Old_PartDesc, Old_ManPartNo, Old_Manuf, Old_Vendor, Old_RefDesi, Old_Qty, New_SbPartNo, New_PartDesc, New_ManPartNo,New_Manuf, New_Vendor, New_RefDesi, New_Qty)...
2
by: James Cooke | last post by:
Hi all, I want to catch a duplicate key exception. I do not want to provide that verbose message from the MSSQL server - I would put a user friendly message out, like "The item you have added...
14
by: Marcus | last post by:
I have a function that simply returns TRUE if it can connect to a particular Sql Server 2005 express, or FALSE if it cannot. I am getting some strange error codes returned when the computer that...
0
by: schm4704 | last post by:
Hi, I was wondering if there is a way to make the SQLException of the new JCC JDBC driver behave and get a decent message out of SQLException.getMessage(). Though I *do* know how to get the...
2
by: lunas | last post by:
hi i am trying to update a table selecting a value from another table and ve written the following codes for it.. import java.sql.*; import java.io.*; import java.util.*; public class...
2
by: rajasoorya | last post by:
Hi, In my application.... i want to identify whther the SQLException caught is a Timeout or any other SQLException. The reason being, i have to show a different msg to the user in case it is a...
0
by: Jim Kennedy | last post by:
ALL DDL does a commit. Hence Drop Table movies; issues a commit. True you don't issue a commit and the driver does not issue a commit, but the server does for all DDL. That is probably where...
2
by: DUMAS64 | last post by:
Exception in thread "main" java.lang.NullPointerException at matchBeans.Results.entryMatchResults(Results.java:112) at matchBeans.Results.displayMenu(Results.java:51) at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.