Hey all. If anyone has read any of my last posts on other sections, you'll know that i have been working on converting an ACCESS db to SQL. Everything is going great so far except for a few bumps, and I'd like to get anyone and everyone's opinion on this.I currently code in ASP classic. The current code design will not work if I convert this site to ASP.NET, but I will later, so please keep this in mind when answering these questions.I have been looking around for way of appending parameters to a sproc from an MSSQL Server. Here are some examples:1- (this is what I used with access): Set cmd = Server.CreateObject("ADODB.Command") cmd.ActiveConnection = dbc cmd.CommandText = "rolyrolls.proc_AddMakeType" cmd.CommandType = adCmdStoredProc Set p = cmd.CreateParameter("usrMakeType", adChar, adParamInput, Len(Form_MakeType), Form_MakeType) cmd.Parameters.Append(p) Set p = cmd.CreateParameter("usrLastModifiedBy", adInteger, adParamInput, Len(Session("ID")), Session("ID")) cmd.Parameters.Append(p) Set rs = Server.CreateObject("ADODB.Recordset") Set rs = cmd.Execute
I changed the parameter name by changing the 'usr' to '@' since I heard that ASP.NET does use/read this, which would be something like: Set p = cmd.CreateParameter("@MakeType", adChar, adParamInput, Len(Form_MakeType), Form_MakeType) cmd.Parameters.Append(p)
2- (found these on the internet/forums and the like)a: Here I noticed they have averything on one line and do not use SET (which I assume will not create an extra object, right?) put the size to 255, being the size of the data-type specified on the server. (more on this later) cmd.Parameters.Append .CreateParameter("@MakeType", adChar, adParamInput, 255, Form_MakeType)
b: I got this from Microsoft. I have never used any output parameters, since I'm not sure it can be done with Access, but will love to use them on SQL. What i don't understand tho, is the 'cmd.CommandText' section with the question marks.[url]http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q164/4/85.asp&NoWebContent=1[/url] Set cn = Server.CreateObject("ADODB.Connection") cn.Open "data source name", "userid", "password" Set cmd = Server.CreateObject("ADODB.Command") Set cmd.ActiveConnection = cn ' Define the stored procedure's inputs and outputs ' Question marks act as placeholders for each parameter for the ' stored procedure cmd.CommandText = "{?=call sp_test(?)}" ' specify parameter info 1 by 1 in the order of the question marks ' specified when we defined the stored procedure cmd.Parameters.Append cmd.CreateParameter("RetVal", adInteger, _ adParamReturnValue) cmd.Parameters.Append cmd.CreateParameter("Param1", adInteger, _ adParamInput) cmd.Parameters("Param1") = 33 cmd.Execute
c: Here's one i found where I assume you give the value after creating the parameter. set DBCON = SetupSQL(Application("DBCON")) Set cmd = Server.CreateObject("ADODB.command") Set cmd.ActiveConnection = DBCON cmd.CommandText = "procIOnlineAuthPwd" cmd.CommandType = 4 'adCmdStoredProc cmd.Parameters.Refresh ' Instead of "cmd.Parameters.Refresh" we can use the followings: ''cmd.Parameters.Append cmd.CreateParameter("RetVal", adInteger, adParamReturnValue) 'cmd.Parameters.Append cmd.CreateParameter("email", adVarChar, adParamInput, 50, "e@ti3.com") 'cmd.Parameters.Append cmd.CreateParameter("backoffice", adInteger, adParamInput) 'cmd.Parameters.Append cmd.CreateParameter("tablename", adVarChar, adParamInput, 20, "tbOnlineAuth_2090") 'cmd.Parameters.Append cmd.CreateParameter("password", adInteger, adParamOutput) cmd.Parameters("@email") = Email cmd.Parameters("@backoffice")=1 cmd.Parameters("@branchID")=branchID cmd.Parameters("@tablename")="tbOnlineAuth" cmd.Parameters("@AuthStartDate")=startdate cmd.Parameters("@AuthStopDate")=enddate cmd.Parameters("@passwordIn")=0 cmd.Parameters("@passwordOut")=0 'Response.Write vbnewline + "Inserting via stored proc." cmd.Execute CheckErr appid, Err, CStr(cmd.CommandText) pwd=cmd.Parameters("@passwordOut") Set cmd = Nothing
d: (last one) I found this one to have two outputs, a return value 9maybe a recordset) along with a value for another parameter. set cmd = server.createobject("ADODB.Command") cmd.ActiveConnection = objConn cmd.CommandType = adCmdStoredProc cmd.CommandText = "sp_po_Add" cmd.Parameters.Append cmd.CreateParameter("@Return", adInteger, _ adParamReturnValue) cmd.Parameters.Append cmd.CreateParameter("@v_ID", adInteger, _ adParamInput, , intVendorID) <... other input params ...> cmd.Parameters.Append cmd.CreateParameter("@OutputRetVal", adInteger, _ adParamOutput, , 0) cmd.Execute() intReturnValue = cmdPurchase("@Return") intOutput = cmdPurchase("@OutputRetVal") set cmd = nothing
So...does anyone out there have anything different? Any preferences? Why do you favor it (for better performance, etc)? What can/will work with both ASP classic and ASP.Net? I thank everyone in advance for their participation.- RoLY roLLs