Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #15877 > unrolled thread

Handling ODBC Connection Errors

Started byGene Wirchenko <genew@ocis.net>
First post2012-09-12 14:03 -0700
Last post2012-09-28 15:29 -0700
Articles 7 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  Handling ODBC Connection Errors Gene Wirchenko <genew@ocis.net> - 2012-09-12 14:03 -0700
    Re: Handling ODBC Connection Errors Gene Wirchenko <genew@ocis.net> - 2012-09-12 19:33 -0700
      Re: Handling ODBC Connection Errors David Mark <dmark.cinsoft@gmail.com> - 2012-09-18 23:19 -0700
        Re: Handling ODBC Connection Errors David Mark <dmark.cinsoft@gmail.com> - 2012-09-18 23:26 -0700
    Re: Handling ODBC Connection Errors "J.R." <groups_jr-1@yahoo.com.br> - 2012-09-27 22:51 -0300
      Re: Handling ODBC Connection Errors Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-28 10:41 +0200
        Re: Handling ODBC Connection Errors "J.R." <groups_jr-1@yahoo.com.br> - 2012-09-28 15:29 -0700

#15877 — Handling ODBC Connection Errors

FromGene Wirchenko <genew@ocis.net>
Date2012-09-12 14:03 -0700
SubjectHandling ODBC Connection Errors
Message-ID<87t1585mmsdg8bqdd8vblsch7esmc36iu2@4ax.com>
Dear JavaScripters:

     Well, I am connecting to SQL Server.  Now, I am trying to handle
the errors that can happen.

     Please note that this is checkout work for what will eventually
be server-side code.  The argument that one should not use direct
access to the DBMS in browser code does not apply here.

     If I do not use try-catch and there is an error in my connection,
my program abends with an error.  Naturally, I want to trap any such
error.  I can do that, but I do not get much information.  Catching to
e gets me an e.name of "Error" and an e.message such as:
          [Microsoft][ODBC SQL Server Driver][SQL Server]Error
converting data type varchar to date.
or (note the variable text):
          [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or
function 'GetPriRow' expects parameter '@theKey', which was not
supplied.

     This is not too terribly usable.  Is there a way to get the
information broken down?  Even just an error number distinguishing the
error messages would be nice.

     Note that the various errors are not the point; being able to
identify so as to possibly handle each error is.

Sincerely,

Gene Wirchenko

[toc] | [next] | [standalone]


#15881

FromGene Wirchenko <genew@ocis.net>
Date2012-09-12 19:33 -0700
Message-ID<70h258trauptcfp6vm5jp5i96h6tonm5pv@4ax.com>
In reply to#15877
On Wed, 12 Sep 2012 14:03:26 -0700, Gene Wirchenko <genew@ocis.net>
wrote:

>Dear JavaScripters:
>
>     Well, I am connecting to SQL Server.  Now, I am trying to handle
>the errors that can happen.
>
>     Please note that this is checkout work for what will eventually
>be server-side code.  The argument that one should not use direct
>access to the DBMS in browser code does not apply here.
>
>     If I do not use try-catch and there is an error in my connection,
>my program abends with an error.  Naturally, I want to trap any such
>error.  I can do that, but I do not get much information.  Catching to
>e gets me an e.name of "Error" and an e.message such as:
>          [Microsoft][ODBC SQL Server Driver][SQL Server]Error
>converting data type varchar to date.
>or (note the variable text):
>          [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or
>function 'GetPriRow' expects parameter '@theKey', which was not
>supplied.
>
>     This is not too terribly usable.  Is there a way to get the
>information broken down?  Even just an error number distinguishing the
>error messages would be nice.
>
>     Note that the various errors are not the point; being able to
>identify so as to possibly handle each error is.

     OK, I did find that .number can be used.  (I so dislike
inaccurate documentation/writeups.)

     What I also found is that the error numbers do not appear to be
the same as those that I see for the same error in SSMS or any
reasonable transformation.  For example, a failed data conversion
(string to date) is 0x80040E14 with ODBC and 343 (0x157) with SSMS.  I
have been unable to find anything relating the two.  If you know,
please give me the URL.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#15987

FromDavid Mark <dmark.cinsoft@gmail.com>
Date2012-09-18 23:19 -0700
Message-ID<b5199f42-1a4f-4178-801e-cb425caca6ce@googlegroups.com>
In reply to#15881
On Wednesday, September 12, 2012 10:33:00 PM UTC-4, Gene Wirchenko wrote:
> On Wed, 12 Sep 2012 14:03:26 -0700, Gene Wirchenko <genew@ocis.net>
> 
> wrote:
> 
> 
> 
> >Dear JavaScripters:
> 
> >
> 
> >     Well, I am connecting to SQL Server.  Now, I am trying to handle
> 
> >the errors that can happen.
> 
> >
> 
> >     Please note that this is checkout work for what will eventually
> 
> >be server-side code.  The argument that one should not use direct
> 
> >access to the DBMS in browser code does not apply here.
> 
> >
> 
> >     If I do not use try-catch and there is an error in my connection,
> 
> >my program abends with an error.  Naturally, I want to trap any such
> 
> >error.  I can do that, but I do not get much information.  Catching to
> 
> >e gets me an e.name of "Error" and an e.message such as:
> 
> >          [Microsoft][ODBC SQL Server Driver][SQL Server]Error
> 
> >converting data type varchar to date.
> 
> >or (note the variable text):
> 
> >          [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or
> 
> >function 'GetPriRow' expects parameter '@theKey', which was not
> 
> >supplied.
> 
> >
> 
> >     This is not too terribly usable.  Is there a way to get the
> 
> >information broken down?  Even just an error number distinguishing the
> 
> >error messages would be nice.
> 
> >
> 
> >     Note that the various errors are not the point; being able to
> 
> >identify so as to possibly handle each error is.
> 
> 
> 
>      OK, I did find that .number can be used.  (I so dislike
> 
> inaccurate documentation/writeups.)
> 
> 
> 
>      What I also found is that the error numbers do not appear to be
> 
> the same as those that I see for the same error in SSMS or any
> 
> reasonable transformation.  For example, a failed data conversion
> 
> (string to date) is 0x80040E14 with ODBC and 343 (0x157) with SSMS.  I
> 
> have been unable to find anything relating the two.  If you know,
> 
> please give me the URL.
> 

The former is an HRESULT. You have to mask off all but the least significant sixteen bits (0x0E14 or 3604 in this case).

http://en.wikipedia.org/wiki/HRESULT

Google returned the phone book for that ODBC error code, but this article indicates it means a duplicate key was ignored.

http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_21026706.html

[toc] | [prev] | [next] | [standalone]


#15988

FromDavid Mark <dmark.cinsoft@gmail.com>
Date2012-09-18 23:26 -0700
Message-ID<d01af60b-5bf0-4f75-938d-0994891d50fb@o30g2000vbu.googlegroups.com>
In reply to#15987
On Sep 19, 2:19 am, David Mark <dmark.cins...@gmail.com> wrote:
> On Wednesday, September 12, 2012 10:33:00 PM UTC-4, Gene Wirchenko wrote:
> > On Wed, 12 Sep 2012 14:03:26 -0700, Gene Wirchenko <ge...@ocis.net>
>
> > wrote:
>
> > >Dear JavaScripters:
>
> > >     Well, I am connecting to SQL Server.  Now, I am trying to handle
>
> > >the errors that can happen.
>
> > >     Please note that this is checkout work for what will eventually
>
> > >be server-side code.  The argument that one should not use direct
>
> > >access to the DBMS in browser code does not apply here.
>
> > >     If I do not use try-catch and there is an error in my connection,
>
> > >my program abends with an error.  Naturally, I want to trap any such
>
> > >error.  I can do that, but I do not get much information.  Catching to
>
> > >e gets me an e.name of "Error" and an e.message such as:
>
> > >          [Microsoft][ODBC SQL Server Driver][SQL Server]Error
>
> > >converting data type varchar to date.
>
> > >or (note the variable text):
>
> > >          [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or
>
> > >function 'GetPriRow' expects parameter '@theKey', which was not
>
> > >supplied.
>
> > >     This is not too terribly usable.  Is there a way to get the
>
> > >information broken down?  Even just an error number distinguishing the
>
> > >error messages would be nice.
>
> > >     Note that the various errors are not the point; being able to
>
> > >identify so as to possibly handle each error is.
>
> >      OK, I did find that .number can be used.  (I so dislike
>
> > inaccurate documentation/writeups.)
>
> >      What I also found is that the error numbers do not appear to be
>
> > the same as those that I see for the same error in SSMS or any
>
> > reasonable transformation.  For example, a failed data conversion
>
> > (string to date) is 0x80040E14 with ODBC and 343 (0x157) with SSMS.  I
>
> > have been unable to find anything relating the two.  If you know,
>
> > please give me the URL.
>
> The former is an HRESULT. You have to mask off all but the least significant sixteen bits (0x0E14 or 3604 in this case).
>
> http://en.wikipedia.org/wiki/HRESULT
>
> Google returned the phone book for that ODBC error code, but this article indicates it means a duplicate key was ignored.
>
> http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q...

As a side note, the "new Google Groups", which features constant and
redundant pop-ups to revert to the old Google groups, botched the
quote. Looks to be a real step backwards, which would have seemed
impossible considering how bad the old one was/is.

Google sucks at seemingly everything save for advertising sales. :(

[toc] | [prev] | [next] | [standalone]


#16215

From"J.R." <groups_jr-1@yahoo.com.br>
Date2012-09-27 22:51 -0300
Message-ID<k42vqp$dq7$1@speranza.aioe.org>
In reply to#15877
On 12/09/2012 18:03, Gene Wirchenko wrote:
> Dear JavaScripters:
>
>       Well, I am connecting to SQL Server.  Now, I am trying to handle
> the errors that can happen.
>
>       Please note that this is checkout work for what will eventually
> be server-side code.  The argument that one should not use direct
> access to the DBMS in browser code does not apply here.
>
>       If I do not use try-catch and there is an error in my connection,
> my program abends with an error.  Naturally, I want to trap any such
> error.  I can do that, but I do not get much information.  Catching to
> e gets me an e.name of "Error" and an e.message such as:
>            [Microsoft][ODBC SQL Server Driver][SQL Server]Error
> converting data type varchar to date.
> or (note the variable text):
>            [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or
> function 'GetPriRow' expects parameter '@theKey', which was not
> supplied.
>
>       This is not too terribly usable.  Is there a way to get the
> information broken down?  Even just an error number distinguishing the
> error messages would be nice.
>
>       Note that the various errors are not the point; being able to
> identify so as to possibly handle each error is.

Hi,
Here is a snippet of the code (JScript / classic ASP) that I wrote to 
deal with a mySQL 5.1 database on my IIS 7 / ASP server:

   var objConnection = {
     cn : Server.CreateObject("ADODB.Connection"),

     open : function () {
       var cnStr = "Driver={MySQL ODBC 5.1 Driver}; Server=localhost; 
Database=xxx; UID=xxx; PWD=xxx";
       if (this.cn.State === 0) {
         this.cn.Open(cnStr);
       }
     },

     close : function () {
       if (this.cn.State !== 0) {
         this.cn.Close();
       }
     },

     sqlExecute : function (strSQL) {
       var success = false, strRet = '';
       try {
         this.cn.Execute(strSQL);
         strRet = 'success';
       } catch (ex) {
         strRet += ex.name +": " +ex.message;
         strRet += '<br />' + ex.message;
         this.cn.Errors.Clear();
       }
       return strRet;
     }
   };

HTH,

--
Joao Rodrigues (J.R.)

[toc] | [prev] | [next] | [standalone]


#16223

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-09-28 10:41 +0200
Message-ID<3171358.h0iHcfXm04@PointedEars.de>
In reply to#16215
J.R. wrote:

> Here is a snippet of the code (JScript / classic ASP) that I wrote to
> deal with a mySQL 5.1 database on my IIS 7 / ASP server:
> 
>    var objConnection = {
>      cn : Server.CreateObject("ADODB.Connection"),
> 
>      open : function () {
>        var cnStr = "Driver={MySQL ODBC 5.1 Driver}; Server=localhost;
> Database=xxx; UID=xxx; PWD=xxx";

This part belongs on the *server*.

> […]


PointedEars
-- 
When all you know is jQuery, every problem looks $(olvable).

[toc] | [prev] | [next] | [standalone]


#16234

From"J.R." <groups_jr-1@yahoo.com.br>
Date2012-09-28 15:29 -0700
Message-ID<421d403d-32a5-47b9-b983-edea58e01357@googlegroups.com>
In reply to#16223
On Friday, 28 September 2012 05:41:25 UTC-3, Thomas 'PointedEars' Lahn  wrote:
> J.R. wrote:
> 
> 
> 
> > Here is a snippet of the code (JScript / classic ASP) that I wrote to
> 
> > deal with a mySQL 5.1 database on my IIS 7 / ASP server:
> 
> > 
> 
> >    var objConnection = {
> 
> >      cn : Server.CreateObject("ADODB.Connection"),
> 
> > 
> 
> >      open : function () {
> 
> >        var cnStr = "Driver={MySQL ODBC 5.1 Driver}; Server=localhost;
> 
> > Database=xxx; UID=xxx; PWD=xxx";
> 
> 
> 
> This part belongs on the *server*.
> 
> 
> 
> > […]

Yes, the above code is server-side ASP / JScript running on a IIS 7 / Windows 2008, accessing a mySQL 5.1 database.

Gene Wirchenko started this topic stating: "Please note that this is checkout work for what will eventually be server-side code.  The argument that one should not use direct access to the DBMS in browser code does not apply here."

Cheers,
Joao Rodrigues (J.R.)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web