Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Can't see the error

Posted on 2006-10-25
14
Medium Priority
?
610 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

824 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