Help with connection.errors

Help with connection.errors

am 11.10.2004 08:54:10 von Anubis

Hello,

I'm trying to get the following information from the Connection.Errors
object,
However it seems to be harder than first thought...


var cnConnection = Server.CreateObject("ADODB.Connection");
cnConnection.ConnectionString = "provider=SQLOLEDB; network=DBMSSOCN;
server=127.0.0.1; database=MYDB001; uid=username; pwd=password;";
cnConnection.Open();


try {

var x = cnConnection.Execute("DECLARE @3293 monint");

} catch (e){

for (i in e){
Response.Write(e.Number);
Response.Write(e.Description);
Response.Write(e.Source);
}

}



In the above I have intentionally created an error in the SQL and I'm
wanting to get the error detail in the catch statement.
Any help with this would be great!

Thanks
-Steve

Re: Help with connection.errors

am 11.10.2004 14:14:35 von reb01501

Anubis wrote:
> Hello,
>
> I'm trying to get the following information from the Connection.Errors
> object,
> However it seems to be harder than first thought...
>
>
> var cnConnection = Server.CreateObject("ADODB.Connection");
> cnConnection.ConnectionString = "provider=SQLOLEDB; network=DBMSSOCN;
> server=127.0.0.1; database=MYDB001; uid=username; pwd=password;";
> cnConnection.Open();
>
>
> try {
>
> var x = cnConnection.Execute("DECLARE @3293 monint");
>
> } catch (e){
>
> for (i in e){
> Response.Write(e.Number);
> Response.Write(e.Description);
> Response.Write(e.Source);
> }
>
> }
>
>
>
> In the above I have intentionally created an error in the SQL and I'm
> wanting to get the error detail in the catch statement.
> Any help with this would be great!
>
> Thanks
> -Steve


e is the jscript error object, not the ADO Connection object's Errors
collection. You have to read the values from that collection explicitly.
response.write(cnConnection.Errors[0].number
etc.

You will need to loop through the collection if more than one error was
raised (which is quite often the case)

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: Help with connection.errors

am 12.10.2004 03:05:16 von Anubis

Hello,

I tried changing it aroung to suit however I still get a 'number' is null or
not an object...


var cnConnection = Server.CreateObject("ADODB.Connection");
cnConnection.ConnectionString = "provider=SQLOLEDB; network=DBMSSOCN;
server=127.0.0.1; database=MYDB001; uid=username; pwd=password;";
cnConnection.Open();


try {

var x = cnConnection.Execute("DECLARE @3293 monint");

} catch (cnConnection){

for (i in cnConnection.Errors){
Response.Write(cnConnection.Errors[i].number);
}

}



Any other suggestions?

Thanks
-Steve





"Bob Barrows [MVP]" wrote in message
news:O9bJev4rEHA.3288@TK2MSFTNGP12.phx.gbl...
> Anubis wrote:
> > Hello,
> >
> > I'm trying to get the following information from the Connection.Errors
> > object,
> > However it seems to be harder than first thought...
> >
> >
> > var cnConnection = Server.CreateObject("ADODB.Connection");
> > cnConnection.ConnectionString = "provider=SQLOLEDB; network=DBMSSOCN;
> > server=127.0.0.1; database=MYDB001; uid=username; pwd=password;";
> > cnConnection.Open();
> >
> >
> > try {
> >
> > var x = cnConnection.Execute("DECLARE @3293 monint");
> >
> > } catch (e){
> >
> > for (i in e){
> > Response.Write(e.Number);
> > Response.Write(e.Description);
> > Response.Write(e.Source);
> > }
> >
> > }
> >
> >
> >
> > In the above I have intentionally created an error in the SQL and I'm
> > wanting to get the error detail in the catch statement.
> > Any help with this would be great!
> >
> > Thanks
> > -Steve
>
>
> e is the jscript error object, not the ADO Connection object's Errors
> collection. You have to read the values from that collection explicitly.
> response.write(cnConnection.Errors[0].number
> etc.
>
> You will need to loop through the collection if more than one error was
> raised (which is quite often the case)
>
> 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: Help with connection.errors

am 12.10.2004 12:44:36 von reb01501

Anubis wrote:
> Hello,
>
> I tried changing it aroung to suit however I still get a 'number' is
> null or not an object...
>
>
> var cnConnection = Server.CreateObject("ADODB.Connection");
> cnConnection.ConnectionString = "provider=SQLOLEDB; network=DBMSSOCN;
> server=127.0.0.1; database=MYDB001; uid=username; pwd=password;";
> cnConnection.Open();
>

Nothing to do with your issue, but the attribute names in this connection
string don't seem to be correct:

cnConnection,Open "provider=SQLOLEDB; " & _
network library=DBMSSOCN; data source=127.0.0.1;" & _
"initial catalog=MYDB001;User ID=username;Password=password"


>
> try {
>
> var x = cnConnection.Execute("DECLARE @3293 monint");
>
> } catch (cnConnection){

No, you still simply do:

catch(e){

The idea is to check for errors in both error handlers. The e object will
contain the error returned by jscript. The connection's Errors collection
will contain te error(s) reported by OLEDB.

>
> for (i in cnConnection.Errors){

You're trying to do a vbscript-style for loop. It does not work that way in
jscript.

if (cnConnection.Errors.count > 0) {
for (i=0;i< cnConnection.Errors.count;i++){

> Response.Write(cnConnection.Errors[i].number);


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"