Pages

Tuesday, October 5, 2010

How to connect to 2 databases in Powerbuilder

How to connect to more than 1 database in Powerbuilder

Some times, you need to connect to more than 1 database in your application. In Powerbuilder, there's 1 object for database connection that you can create programmatically. The object call: TRANSACTION.

In this example, I will explain how to connect to 2 databases, which mean 1 is with default database connection object (named SQLCA), and the other is the object that we create mannualy.

I'm using Microsoft SQL Server 2000 as a database engine.

First of all, we need to create a transaction object. It's depending on what the purpose of the transaction. You can declare with Instance, Global or even Local variable for this object.

Let's say we create Instant Variable, called: SQLCAID

transaction SQLCAID;


On Open Event, we must create first the transaction object, then setup the properties of the object.

Note: You can try first on the Database painter, to get the right property values, and to make sure that you can connect to the database. Then copy and paste the script.

SQLCAID = CREATE transaction;
SQLCAID.DBMS = "MSS Microsoft SQL Server"
SQLCAID.Database = "database1"
SQLCAID.LogPass = "password"
SQLCAID.ServerName = "localhost"
SQLCAID.LogId = "sa"
SQLCAID.AutoCommit = False
SQLCAID.DBParm = ""


// Try to connect the database
// REMEMBER, you must add USING SQLCAID statement at the end of your SQL Statement, every times you want to execute your database that related with SQLCAID transaction

CONNECT USING SQLCAID;

// Trap the error if the object can't connect to database

IF SQLCAID.SQLCode <> 0 THEN
    MessageBox("Connection Error to "+SQLCAID.Database, &
        "Unable to connect to database. Make sure you type the correct password." + &
        "~r~nTry Again. If the problem persists, contact IT Officer" + &
        "~r~nSQLDBCode = " + String(SQLCAID.SQLDBCode) + &
        "~r~nSQLErrText = " + SQLCAID.SQLErrText)
   HALT
END IF



At the other side, you still must declare the DEFAULT SQLCA transaction object.

SQLCA.DBMS = "MSS Microsoft SQL Server"
SQLCA.Database = "databasedefault"
SQLCA.LogPass = "password"
SQLCA.ServerName = "localhost"
SQLCA.LogId = "sa"
SQLCA.AutoCommit = False
SQLCA.DBParm = ""


// Just for make sure that you connect with SQLCA transaction

CONNECT USING SQLCA;


// Trap the error if the object can't connect to database
IF SQLCA.SQLCode <> 0 THEN
    MessageBox("Connection Error to "+SQLCA.Database, &
        "Unable to connect to database. Make sure you type the correct password." + &
        "~r~nTry Again. If the problem persists, contact IT Officer" + &
        "~r~nSQLDBCode = " + String(SQLCA.SQLDBCode) + &
        "~r~nSQLErrText = " + SQLCA.SQLErrText)
   HALT
END IF


Now you already connected with 2 databases.

Remember, always put USING SQLCA or USING SQLCAID statement at the end of your SQL Statement to make sure that the SQL Statement will execute into the database that you purpose

Example:

string sProductID, sProductName

// will retrieve the product_id and product_name column from SQLCAID transaction
SELECT product_id, product_name INTO :sProductID, :sProductName FROM product_master USING SQLCAID;

// will retrieve the product_id and product_name column from SQLCA (Default) transaction
SELECT product_id, product_name INTO :sProductID, :sProductName FROM product_master USING SQLCA;
»»  READMORE...

Sunday, October 3, 2010

AVG Anti-Virus 2011 Free Edition Short Review

Release on Sept 28th, 2010, AVG Anti-Virus Free Edition 2011 brings some new features.

With around 110 MB file size, at least 2 new features added on this version.






1. Social Network Protection
 
With tag line: Keeps social networks safe for you and your friends, AVG brings the protection to all use who use the social network application. AVG will protect all the send and receive links freely knowing they've all been automatically checked for safety,

2. PC Analyzer

Module to scan your PC and report errors that affect its performance. There are 4 categories that will be analyze, including Registry, Junk Files, Fragmentation and Broken Shortcuts. You need to download separate module called: AVG PC TuneUp to fix all the errors. You only have once time free to fix the error, then you must purchase yearly to unlimited tuneup.

You can download the AVG Anti-virus 2011 Free Edition from their official site or via CNET's download.com
»»  READMORE...