Solved

Can't see the error

Posted on 2006-10-25
14
600 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
  • 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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 500 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now