?
Solved

Can't see the error

Posted on 2006-10-25
14
Medium Priority
?
608 Views
Last Modified: 2008-02-01
Hi,
My code behind gathers the input parameters and calls an SP.
This SP contains an insert statement.

When I run my aspx page, fill in the form and hit submit I get an error:
System.Data.SqlClient.SqlException was unhandled by user code
  Class=15
  ErrorCode=-2146232060
  LineNumber=1
  Message="Line 1: Incorrect syntax near 'InsertNewVApplication'."
  Number=170
  Procedure=""
  Server="devBoxDVMAIN"
  Source=".Net SqlClient Data Provider"
  State=1

judging by the error it looks like it is being returned from SQL.
I ran a trace and captured the code the .net page is passing. I then ran this code in query analyser and get the same error Incorrect syntax near 'InsertNewVApplication'.

The first part of the code is.....
exec sp_executesql N'InsertNewVApplication', N'@strSurname nvarchar(8),@strFirstName nvarchar(3),@strPrefName nvarchar(4000),@strOtherName nvarchar(4000),@strResAddress nvarchar(4000) etc etc

Anything obvious there?
The aspx code to call the SP is...
Dim Cmd As New Data.SqlClient.SqlCommand("InsertNewVApplication", Conn)
then we define the insert parameters
Conn.Open()
        Cmd.ExecuteNonQuery()
        Conn.Close()
        Cmd.Dispose()
0
Comment
Question by:QPR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +3
14 Comments
 
LVL 6

Expert Comment

by:Roopesh_7
ID: 17808464
hey no need for a " ("  i mean before starting parametre?
exec sp_executesql ('InsertNewVApplication',@strSurname nvarchar(8),@strFirstName nvarchar(3),@strPrefName nvarchar(4000),@strOtherName nvarchar(4000),@strResAddress nvarchar(4000) etc etc)
0
 
LVL 29

Author Comment

by:QPR
ID: 17808641
I don't put any "("s in there. e.g. nvarchar(8)
That is generated by VS/ADO/ODBC/I dont know  :)
0
 
LVL 29

Author Comment

by:QPR
ID: 17808643
like this

Dim Conn As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("ConnString").ConnectionString)
        Dim Cmd As New Data.SqlClient.SqlCommand("InsertNewVApplication", Conn)
        With Cmd
            .Parameters.AddWithValue("@strSurname", strSurname)
            .Parameters.AddWithValue("@strFirstName", strFirstNames)
            .Parameters.AddWithValue("@strPrefName", strPrefName)
            etc etc
        End With

        Conn.Open()
        Cmd.ExecuteNonQuery()
        Conn.Close()
        Cmd.Dispose()
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:AaronAbend
ID: 17808932
try SqlCommand("exec InsertNewVApplication"
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17808939
Run the SQL server profiler first, and then your .Net Page.
Watch what is coming on the Profiler window.
Now copy it and run it on Query analyzer

Also remove the "  N'  " for nvarchar params

exec sp_executesql N'InsertNewVApplication', @strSurname nvarchar(8),@strFirstName nvarchar(3),@strPrefName nvarchar(4000),@strOtherName nvarchar(4000),@strResAddress nvarchar(4000)
0
 
LVL 29

Author Comment

by:QPR
ID: 17808942
Thatr is exactly what I did.
Extract from my original post....

I ran a trace and captured the code the .net page is passing. I then ran this code in query analyser and get the same error Incorrect syntax near 'InsertNewVApplication'.
0
 
LVL 29

Author Comment

by:QPR
ID: 17808945
try SqlCommand("exec InsertNewVApplication"

which line does this replace?
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17808986

this will work in qa
exec sp_executesql InsertNewVApplication @strSurname nvarchar(8),@strFirstName nvarchar(3),@strPrefName nvarchar(4000),@strOtherName nvarchar(4000),@strResAddress nvarchar(4000)
0
 
LVL 29

Author Comment

by:QPR
ID: 17809055
So the problem is the N' before the SP name?
If so then how do I stop the aspx from generating this uneccesary char?
0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 17809205
put this at the bottom of the sproc and run the sproc from sql management with the params asp.net is passing in to see if sql is throwing error.


IF @@ERROR <> 0
  BEGIN
    select @@ERROR ;
  END
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 2000 total points
ID: 17809303
You need to set your command type to a stored procedure.  It's trying to evaluate it as a sql statement (Text).

Dim Cmd As New Data.SqlClient.SqlCommand("InsertNewVApplication", Conn)
cmd.CommandType = System.Data.CommandType.StoredProcedure

0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17809304
>So the problem is the N' before the SP name?

I think there is a comma after that sp name also
0
 
LVL 29

Author Comment

by:QPR
ID: 17809587
Dean.... as I said in the original question. I have run the sql (that .NET is producing) in QA and yes it is SQL that is throwing the error.

Aneesh, the N' and , are both produced by .NET based on the above code

Clockwatcher, I'll give this a go when I'm back at work tomorrow.
0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 17824790
thats why you need to add error handling to sproc

IF @@ERROR <> 0
  BEGIN
    select @@ERROR ;
  END

it is hard to catch sql errors using cmd eg like a primary key violation especially if you are using executenonquery, maybe what you can do is do the insert, check amount of rows return and if -1 or 0 I think then run another sproc to get the last error thrown...

good luck
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question