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


Groups > comp.lang.javascript > #16215

Re: Handling ODBC Connection Errors

From "J.R." <groups_jr-1@yahoo.com.br>
Newsgroups comp.lang.javascript
Subject Re: Handling ODBC Connection Errors
Date 2012-09-27 22:51 -0300
Organization Aioe.org NNTP Server
Message-ID <k42vqp$dq7$1@speranza.aioe.org> (permalink)
References <87t1585mmsdg8bqdd8vblsch7esmc36iu2@4ax.com>

Show all headers | View raw


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

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web