简体   繁体   中英

Error after switching from ODBC DSN connection to OLEDB

I've been having timeout and login connection issues from my ASP application to my SQL Server database. My hosting provider suggested changing my connection string from ODBC DSN to OLEDB. Once I did that I get this error when executing my first stored procedure.

Procedure or function 'storedproc' expects parameter '@param1', which was not supplied.

Here is my connection string

Dim objconn
Set objconn = Server.CreateObject("ADODB.Connection")
objconn.open "Provider=SQLOLEDB;Data Source=localhost\sqlexpress;Initial Catalog=db;user id=user;password=pw"

Here is my stored proc call

Dim objrs, cmd
Set cmd = Server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = objconn
cmd.CommandText = "storedproc"
cmd.Parameters.Append(cmd.CreateParameters("param1",adDouble,adParamInput,,session("param1")))
Set objrs = Server.CreateObject("ADODB.Recordset")
objrs.CursorLocatoin = adUseClient
objrs.Open cmd

Any ideas why my proc call doesn't work with a different connection string?

There are a few typos, .CreateParameters => .CreateParameter and .CursorLocatoin => .CursorLocation
I've ignored them because looks like typos only applies to the question.

CommandType Property

If the CommandType property value is set to the default value, adCmdUnknown, you may experience diminished performance because ADO must make calls to the provider to determine if the CommandText property is an SQL statement, a stored procedure, or a table name. If you know what type of command you are using, setting the CommandType property instructs ADO to go directly to the relevant code. If the CommandType property does not match the type of command in the CommandText property, an error occurs when you call the Execute method.

As I understand, action is vary depending to the provider when the CommandType is not specified.

I tracked the queries using the SQL Server Profiler. What I saw is with OLEDB Provider, the command objects without CommandType property executes a query without parameter on the background something like that : Exec storedproc , this means it works properly if the procedure is parameterless. However it should have been Exec storedproc parametervalue . On the other hand, same code works like a charm on MySQL as you said.

So, need to specify cmd.CommandType as adCmdStoredProc that equals to 4 , then your code will work.
BTW, It's -1 ( adCmdUnknown ) by default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM