Professional Web Applications Themes

Help with connection.errors - ASP Database

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...

  1. #1

    Default Help with connection.errors

    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




    Anubis Guest

  2. #2

    Default Re: Help with connection.errors

    Anubis wrote: 


    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"


    Bob Guest

  3. #3

    Default Re: Help with connection.errors

    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]" <SPAMcom> wrote in message
    news:phx.gbl... 
    >
    >
    > 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"
    >
    >[/ref]


    Anubis Guest

  4. #4

    Default Re: Help with connection.errors

    Anubis wrote: 

    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"

     

    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.
     

    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++){
     


    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"


    Bob Guest

Similar Threads

  1. ODBC Data Source Won't Recover from Connection Errors
    By spikehenning in forum Coldfusion Database Access
    Replies: 2
    Last Post: August 3rd, 04:41 PM
  2. Constant Connection Errors - Execption
    By csgdemon in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: May 4th, 05:13 PM
  3. Replies: 6
    Last Post: October 8th, 01:58 PM
  4. Access dbase connection string errors
    By J. Muenchbourg in forum ASP
    Replies: 3
    Last Post: August 8th, 10:15 PM
  5. Trap "connection pool" errors
    By Sean Nolan in forum ASP.NET General
    Replies: 1
    Last Post: July 11th, 02:59 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139