Problem calling SQL Server stored procedure from classic ASP

Hi, I'm trying to call a SQL Server 2005 stored procedure from a classic ASP page using ADO.  I have verified that the connection string is correct, the user login has permissions to execute the procedure in question, and that the procedure itself functions properly.  I can reproduce the results in the ASP page by passing in hard-coded SQL.  However, when I call .Execute, I get this error:

Microsoft OLE DB Provider for SQL Server error '80040e14'
Syntax error or access violation

The relevant code snippet is below:

Dim Cmd : Set Cmd = Server.CreateObject("ADODB.Command")
Dim root
With Cmd
  .ActiveConnection = Cn
  .CommandType = adCmdStoredProc
  .CommandText = "getNAIC-ID"
  .Parameters.Append .CreateParameter("@naic_code", adVarChar, adParamInput, 15, Session("SalesImaging_CompanyNum"))
  .Parameters.Append .CreateParameter("@naic_id", adInteger, adParamOutput, ,0)
  .Execute ,,adExecuteNoRecords
  root = .Parameters("@naic_id")
End With

Sorry if I'm missing the obvious - thanks!
Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
or like this:

  .CommandText = "[getNAIC-ID]"
What line do you get the error on?
.CommandText = "getNAIC-ID"

I think the error is due to the " - " in your stored porcedure name . Please change the SP name, as for eg. "getNAIC_ID"  and check it.
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

jgbaderAuthor Commented:

That worked perfectly.  As a matter of curiosity, is there a particular reason why those brackets should matter?  I've never needed them before.  Of course, all I've used before is .NET web apps, not classic ASP.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
savitha actually gave you the reason. the "-" would be interpreted, without the [] around the name, as math operation...
jgbaderAuthor Commented:
Indeed.  A math operation?  I hadn't thought of that.  Thanks again!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.