Creating Connection Objects

This section describes how to create a connection object.
  1. Load the wsodbc.dll as previously described if you have not already done it.
  2. Create the connection parameters as previously described.
  3. Create the connection object. This will establish a new ODBC connection using the connection parameters you previously defined. An example is shown below:
    db = new Odbc(dbTest);

    We recommend placing the connection object in a try-catch block so as to ensure proper error handling. An example script is shown below.

    function ODBCconnect(dbase) 
    {
      var sConnectTrusted = 'Driver={SQL Native Client};Server={'+dbase.server+'};Database={'+dbase.dbname+'};'Trusted_Connection:Yes'
      var sConnectUser = 'Driver={SQL Native Client'};Server={'+dbase.server+'};Database={'+dbase.dbname+'};UID={+dbase.user+'};PWD={'+dbase.pass+'}';
      var sConnect = '';
      
      if(dbase.user) sConnect = sConnectUser;
      else sCOnnect = sConnectTrusted;
      println('Connecting with '+sConnect);
      try{
        db = new Odbc(sConnect);
        }
        catch(err){
          message("E: Error with database conectivity.");
          println("> error with DB:",err.description);
          return NULL;
        }
      println("Connected to "+db.dbms+'. Server '+dbase.server+' Database '+dbase.dbname);
      
      return db;
    }
  4. Proceed to the Using SQL Create Statements section.