Re: Pramererized Stored Proc returning error when run from vb.net code

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Narayana Vyas Kondreddi (answer_me_at_hotmail.com)
Date: 07/09/04


Date: Fri, 9 Jul 2004 08:27:31 +0100

Can you run Profiler on the server (trace SQL:BatchStarting, SP:Starting
events) to see what's actually coming into SQL Server, from your app.
That'll give you the clue.

-- 
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
"Anand Sagar" <ba_sagar@yahoo.com> wrote in message
news:%23FoIPBYZEHA.1508@TK2MSFTNGP09.phx.gbl...
> I created a stored procedure
>
> create proc getcontact @acno varchar(30)
> as
> select * from contact1 where accountno = @acno
>
>
> When I execute this sp in the Query Analayser like this
>
> getcontact '95112933591388844Gab'
>
> it works.
>
>
>
> But when I try to execute from my asp.net code,
>
> Dim Con As New SqlConnection("server=.;uid=sa;pwd=;database=testgm")
>        Con.Open()
>
>        Dim cmd As New SqlCommand("getcontact", Con)
> cmd.Parameters.Add(New SqlParameter("@acno", "95112933591388844Gab"))
>
>        Dim dr As SqlDataReader = cmd.ExecuteReader()
>
> at this point the program returns an error saying
>
> *****************************
> Line 1: Incorrect syntax near 'getcontact'.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
>
> Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect
> syntax near 'getcontact'.
>
> Source Error:
>
>
> Line 108:
> Line 109:
> Line 110:        Dim dr As SqlDataReader = cmd.ExecuteReader()
> Line 111:        'Dim da As New SqlDataAdapter(cmd)
> Line 112:
>
>
> Source File: f:\GoldMine_Net\Load_LeftblankCombo.aspx.vb    Line: 110
>
> *****************************************
>
> Why does it say  Incorrect syntax near 'getcontact'. when the same proc is
> succesful run from Query Analyser tool ?
>
> Please help
>
> Thanks,
> Anand Sagar.
>
>


Relevant Pages

  • Re: One Web Service updates SQL, another cant?
    ... section of the Trace Properties dialog. ... And then I start getting the database closed errors on subsequent calls. ... > The error suggests that somehow the connection to SQL Server is being ... Could we have a look at your connection string? ...
    (microsoft.public.sqlserver.security)
  • RE: cannot delete a record in sql server 2005 through asp program
    ... Using trace script he provided and trace file created by the script. ... SQL Server database by the asp application. ... Microsoft Online Community Support ... a Microsoft Support Engineer within 2 business day is acceptable. ...
    (microsoft.public.sqlserver.programming)
  • Re: Profiler Security
    ... There's no way to restrict what a user of trace can see - if they ... etc. coming into SQL Server. ... >> want to assign the developers the sys admin sql role. ...
    (microsoft.public.sqlserver.security)
  • Re: Auditing sql server at runtime
    ... SQL Server native tools don't do any port sniffing. ... Use SQL Profiler to define your trace, ... Create a SQL Agent job to run that trace, paste the script into it. ...
    (microsoft.public.sqlserver.clients)
  • Re: Auditing sql server at runtime
    ... "Manpreet Singh" wrote in message ... DB Dev SQL Server 2005 ... Use SQL Profiler to define your trace, ... Create a SQL Agent job to run that trace, ...
    (microsoft.public.sqlserver.clients)