Solved

Can't see the error

Posted on 2006-10-25
14
605 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

615 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