Forum Moderators: open
My big question though - is it really needed? I can UNDERSTAND the benefits, but here is for instance:
I have a basic query that I run on many pages. It brings back a list of classes:
var rsChoirs = Server.CreateObject("ADODB.Recordset");
rsChoirs.ActiveConnection = conn;
rsChoirs.Source = "SELECT Choir FROM Choirs WHERE schCode = '" + scode + "'";
rsChoirs.CursorType = 0;
rsChoirs.CursorLocation = 2;
rsChoirs.LockType = 3;
rsChoirs.Open();
conn is defined in an include file.
So I made a stored procedure for this query, but if I were to call it from my ASP program I'd still need most of the same code:
var rsChoirs = Server.CreateObject("ADODB.Recordset");
rsChoirs.ActiveConnection = conn;
rsChoirs.Source = "CALL spCLASSES(scode)";
rsChoirs.CursorType = 0;
rsChoirs.CursorLocation = 2;
rsChoirs.LockType = 3;
rsChoirs.Open();
At least I think I do - I'm not certain yet that this is correct.
So where is the benefit?
set oCMD = CreateObject("adodb.command")
with oCMD
.CommandType = adCmdStoredProc
.CommandText = "spCLASSES"
.Parameters.Append .CreateParameter("@parametername", adVarchar, adParamInput, 25, scode)
.ActiveConnection = conn
end with
set oRST = CreateObject("adodb.recordset")
With oRST
.Open oCMD, , adOpenForwardOnly, adLockReadOnly, adCmdStoredProc
If Not .EOF Then
aResults = .GetRows()
Else
aResults = Null
End If
.Close
end with
set oRST = Nothing
set oCMD = Nothing
Either way will work, of course, SQL or stored procedure. But perhaps this example starts to show what is possible with stored procedures.
Here's more:
- A sproc is a re-usable object that can be executed from any web page, desktop, dts package etc...
- Reduces network traffic by not passing large pass-thru sql strings
- Lets you isolate database logic from the front end
Easy_Coder- I dont know about mySQL, but with MSSQL I use a quick "Refresh" to avoid the paramater type declarations:
set objCommand = Server.CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConn
objCommand.CommandText = "spName"
objCommand.CommandType = adCmdStoredProc
objCommand.Parameters.Refresh
objCommand.Parameters("@Name")= Value
objCommand.Execute
ReturnValue = objCommand.Parameters("@ReturnValue").Value
The way to call sproc?
Obviously before shooting in the dark I shall read the tutorial.
When you are speaking about reusable object
are you also ref to an object that in OOP PHP we will instantiate by calling a new whatever object name?
It's a reusable object in that you can extend them to just about any other application; not just a single web site. The beauty of that is ease of maintenance. If you need to make an adjustment to the query then it can be done from a single location versus the n number of places where the pass thru sql exists. Now, if you change the interface then you might need to re-wire the command unless you've created a command wrapper.
In my situation I have an accounting system, web based dashboard, website, dts services and web services all firing and sharing the same stored procedures.
But access is pretty much (at the present time) reserved to those managing their own server, I do not think that most ISP are ready to update before the release of a few new versions and lots of proven track records.
I will start by updating my test bed.