Calling stored procedure - JScript
Calling stored procedure - JScript
am 03.02.2006 11:48:09 von Roland Hall
I've never done this before using JScript. Having a little trouble finding
information on it.
Source:
var conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\databases\\ado.mdb"
var comm = Server.CreateObject("ADODB.Command")
comm.CommandText = "qUsers"
comm.CommandType = adCmdStoredProc
comm.ActiveConnection = conn.Open()
var rs = Server.CreateObject("ADODB.Recordset")
rs.CursorType = adOpenForwardOnly
rs = comm.Execute()
if(!rs.EOF) {
var arr = rs.GetRows()
arr = arr.toArray()
var col = rs.Fields.count
rs.Close()
rs = null
conn.Close()
conn = null
for(row=0; i
did = arr[row]
dusername = arr[row+1]
dfirstname = arr[row+2]
dlastname = arr[row+3]
demail = arr[row+4]
Response.Write("id:" + did + "
")
Response.Write("username: " + dusername + "
")
Response.Write("name: " + dfirstname + " " + dlastname + "
")
Response.Write("email: " + demail + "
")
}
}
My error is on this line:
comm.ActiveConnection = conn.Open()
ADODB.Command error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in
conflict with one another.
/lab/adojs.asp, line 9
I may have other errors down the line I can't see yet but this is where I'm
at.
TIA...
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Re: Calling stored procedure - JScript
am 03.02.2006 12:25:38 von Roland Hall
"Roland Hall" wrote in message
news:eO$DU9KKGHA.2992@tk2msftngp13.phx.gbl...
: I've never done this before using JScript. Having a little trouble
finding
: information on it.
: Source:
:
: var conn = Server.CreateObject("ADODB.Connection")
: conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
: Source=c:\\databases\\ado.mdb"
: var comm = Server.CreateObject("ADODB.Command")
: comm.CommandText = "qUsers"
: comm.CommandType = adCmdStoredProc
: comm.ActiveConnection = conn.Open()
: var rs = Server.CreateObject("ADODB.Recordset")
: rs.CursorType = adOpenForwardOnly
: rs = comm.Execute()
:
: if(!rs.EOF) {
: var arr = rs.GetRows()
: arr = arr.toArray()
: var col = rs.Fields.count
: rs.Close()
: rs = null
: conn.Close()
: conn = null
: for(row=0; i
: did = arr[row]
: dusername = arr[row+1]
: dfirstname = arr[row+2]
: dlastname = arr[row+3]
: demail = arr[row+4]
: Response.Write("id:" + did + "
")
: Response.Write("username: " + dusername + "
")
: Response.Write("name: " + dfirstname + " " + dlastname + "
")
: Response.Write("email: " + demail + "
")
: }
: }
:
: My error is on this line:
:
: comm.ActiveConnection = conn.Open()
:
: ADODB.Command error '800a0bb9'
: Arguments are of the wrong type, are out of acceptable range, or are in
: conflict with one another.
:
: /lab/adojs.asp, line 9
:
: I may have other errors down the line I can't see yet but this is where
I'm
: at.
Ok, I got it.
var conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\domains\\kiddanger.com\\db\\ado.mdb"
conn.Open()
var rs = Server.CreateObject("ADODB.Recordset")
rs.CursorType = adOpenForwardOnly
rs = conn.Execute("qUsers")
if(!rs.EOF) {
var arr = rs.GetRows()
arr = arr.toArray()
var col = rs.Fields.count
rs.Close()
rs = null
conn.Close()
conn = null
for(row=0; row
did = arr[row]
dusername = arr[row+1]
dfirstname = arr[row+2]
dlastname = arr[row+3]
demail = arr[row+4]
Response.Write("id:" + did + "
")
Response.Write("username: " + dusername + "
")
Response.Write("name: " + dfirstname + " " + dlastname + "
")
Response.Write("email: " + demail + "
")
}
}
But I decided to change this line:
rs = conn.Execute("qUsers")
to:
conn.qUsers(rs)
Which is closer to how I do it in VBS.
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Re: Calling stored procedure - JScript
am 03.02.2006 12:35:52 von reb01501
Roland Hall wrote:
>
> My error is on this line:
>
> comm.ActiveConnection = conn.Open()
>
> ADODB.Command error '800a0bb9'
> Arguments are of the wrong type, are out of acceptable range, or are
> in conflict with one another.
>
I'm not going to test it, but why wouldn't you do:
conn.Open();
comm.ActiveConnection=conn;
Actually, I think the problem may be due to the lack of optional arguments
in jscript: you have to supply all 4 arguments to the Open method.
connection.Open ConnectionString, UserID, Password, Options
So, it should probably look like:
conn.Open("","","",null)
or, maybe:
conn.Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\databases\\ado.mdb","","",null)
Does your stored procedure have output parameter(s)? Or are you going to
read the Return parameter value? If not, I wonder if the
procedure-as-connection-method technique would work in jscript ... ?
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Re: Calling stored procedure - JScript
am 03.02.2006 12:36:55 von reb01501
Roland Hall wrote:
>>
> But I decided to change this line:
> rs = conn.Execute("qUsers")
>
> to:
> conn.qUsers(rs)
>
> Which is closer to how I do it in VBS.
Hah! It does work in jscript!
Bob
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Re: Calling stored procedure - JScript
am 03.02.2006 14:01:37 von Roland Hall
"Bob Barrows [MVP]" wrote in message
news:%23cuJgYLKGHA.2088@TK2MSFTNGP11.phx.gbl...
: Roland Hall wrote:
: >>
: > But I decided to change this line:
: > rs = conn.Execute("qUsers")
: >
: > to:
: > conn.qUsers(rs)
: >
: > Which is closer to how I do it in VBS.
:
: Hah! It does work in jscript!
Yes, using what you taught me in VBS.
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Re: Calling stored procedure - JScript
am 03.02.2006 14:07:28 von Roland Hall
"Bob Barrows [MVP]" wrote in message
news:OE5c6XLKGHA.1676@TK2MSFTNGP09.phx.gbl...
: Roland Hall wrote:
: >
: > My error is on this line:
: >
: > comm.ActiveConnection = conn.Open()
: >
: > ADODB.Command error '800a0bb9'
: > Arguments are of the wrong type, are out of acceptable range, or are
: > in conflict with one another.
: >
:
: I'm not going to test it, but why wouldn't you do:
: conn.Open();
: comm.ActiveConnection=conn;
:
: Actually, I think the problem may be due to the lack of optional arguments
: in jscript: you have to supply all 4 arguments to the Open method.
:
: connection.Open ConnectionString, UserID, Password, Options
:
: So, it should probably look like:
: conn.Open("","","",null)
:
: or, maybe:
: conn.Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data
: Source=c:\\databases\\ado.mdb","","",null)
:
: Does your stored procedure have output parameter(s)? Or are you going to
: read the Return parameter value? If not, I wonder if the
: procedure-as-connection-method technique would work in jscript ... ?
I'm not real ept on the ADODB.Command. I'm assuming it all works the same
as VBS except you need the ( ).
I'm just reading what is returned in the record set.
This is the link to the code I posted that worked:
http://kiddanger.com/lab/adojs.asp
I'm not a fan of jscript on the server-side except to steal from it for
sorting an array. I was just trying to see if I could do it to help someone
else. The intellisense in VS offers the 4 parameters.
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Re: Calling stored procedure - JScript
am 03.02.2006 14:10:18 von Roland Hall
"Bob Barrows [MVP]" wrote in message
news:%23cuJgYLKGHA.2088@TK2MSFTNGP11.phx.gbl...
: Roland Hall wrote:
: >>
: > But I decided to change this line:
: > rs = conn.Execute("qUsers")
: >
: > to:
: > conn.qUsers(rs)
: >
: > Which is closer to how I do it in VBS.
:
: Hah! It does work in jscript!
I haven't tried passing parameters to it but I assume it works the same.
conn.qUsers(param1, param2, rs)
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Re: Calling stored procedure - JScript
am 27.02.2006 11:09:41 von mmcginty
"Bob Barrows [MVP]" wrote in message
news:OE5c6XLKGHA.1676@TK2MSFTNGP09.phx.gbl...
> Roland Hall wrote:
>>
>> My error is on this line:
>>
>> comm.ActiveConnection = conn.Open()
>>
>> ADODB.Command error '800a0bb9'
>> Arguments are of the wrong type, are out of acceptable range, or are
>> in conflict with one another.
>>
The method connection.Open does not return a connection object,
(typeof(conn.Open()) == "undefined") is a true expression. So it's the
assignment of that to ActiveConnection that's the rub.
> I'm not going to test it, but why wouldn't you do:
> conn.Open();
> comm.ActiveConnection=conn;
>
> Actually, I think the problem may be due to the lack of optional arguments
> in jscript: you have to supply all 4 arguments to the Open method.
JScript does not lack optional arguments, it just lacks syntax that allows
ommission of one argument with inclusion of another that's later in the
list. So if you want to omit an argument, you must be prepared to omit all
that come after it in the arguments list as well.
Functions in JScript implicitly have a variable length argument list -- in
fact, declared arguments are (besides the fact that they make the code much
easier to read) really more of a formality than anything else, thanks to the
JScript function object's arguments property. Here's an example:
// Accepts a variable number of arguments; returns the value of the
// first argument in its list that is neither null nor an empty string
//
function coalesce()
{
var i;
for (i = 0; i < arguments.length; i++)
{
if ((arguments[i] != null) && (arguments[i] != ""))
return arguments[i];
}
return "";
}
[from one of Bob's earlier posts]
> Hah! It does work in jscript!
Why wouldn't it? :-) I *am* a fan of server-side JScript, because its
exception handling construct is more flexible and capable than is its
counterpart in VBS. I've also found it to perform better in some cases (and
haven't noticed any where it performed worse -- which is not to say there
are none, nor even that I have never encountered any, just that none have
drawn my attention.)
The only thing I missed about VBS is that VBS' built-in functions tend to be
a little more intuitive/easier to use... so I coded work-alikes for the ones
I use heavily... but to each his own. :-)
My 2 cents,
Mark
> connection.Open ConnectionString, UserID, Password, Options
>
> So, it should probably look like:
> conn.Open("","","",null)
>
> or, maybe:
> conn.Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=c:\\databases\\ado.mdb","","",null)
>
> Does your stored procedure have output parameter(s)? Or are you going to
> read the Return parameter value? If not, I wonder if the
> procedure-as-connection-method technique would work in jscript ... ?
>
> Bob Barrows
> --
> Microsoft MVP - ASP/ASP.NET
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"
>