Before Working on any data window object while coding,
PowerBuilder should have database connection Profiles -Connection for using dB
objects in code or create data window.
For Setup of Db profile, we use below option:
Once, This is setup , now we could create datawindows . To clear this out, This is just for validating db objects and designing datawindow at development.
For using the Database while running the application, you need to configure connection using SQLCA object.
SQLCA- Transaction object, used to communicate with your
database.
I am using Sql server Db example here:
We can use this code to initialize SQLCA object parameters
SQLCA.DBMS = "SNC SQL Native Client(OLE DB)"
SQLCA.ServerName = "localhost"
SQLCA.LogId = "sa"
SQLCA.DBParm = "Database='trydb',TrustedConnection=1"
Connecting/ Disconnecting to SQLCA :
connect Using SQLCA;
Code b/w the block to access the db objects.
disconnect using SQLCA;
It is a good practice to use connect statement at open() & disconnect statement at close() event of window or application.
Using connection Service for db connection
We could Create connection service using connection wizard and use in our code to handle db connection.
of_getconnectioninfo() is the one having SQLCA parameter initialized .the code is auto-generated while creating this connection object ,selecting the db parameters .
To use this connection , we can use the following Code described in screenshot or else in our way how we want it to be implemented.
No comments:
Post a Comment