November 30, 2005

 

Connect to PostgreSQL from Pragma 6

 

Connecting to a Database on your Machine

You can view the PostgreSQL data from Pragma 6.

In Pragma 6 go to the 'View', 'SQL Data...' menu entry. If you are not yet connected you will get the Pragma 'PostgreSQL Connect Dialog', boldly stating that you are not connected.

If this is the first time you try to connect to PostgreSQL from Pragma, the Connect script and the Tables combo will be empty, otherwise the Connect script will show (like the picture above) you how you connected the last time.

 Hit the connect button and the Select Data Source dialog (a Windows utility) will appear.

More than likely, your window will not show any dsn files.  You must create one by hitting the New... button.  

The sequence that follows is rather confusing (not Pragma's fault) but you should get to the window shown above, where you select the PostgreSQL driver.  You should have the PostgreSQL driver already installed since the PostgreSQL installation will automatically take care of that.  If you cannot find the driver something went wrong with the installation and you should start troubleshooting by going to the 'Control Panel', 'Administrative Tools', 'Data Sources (ODBC)', 'Drivers'.  If the driver has not been installed you must install it manually.  You can find the driver {a DLL) in a directory of the PostgreSQL installation.  Or repeat the PostgreSQL installation.

This whole operation is to create a dsn file that tells Windows what ODBC driver you want to use. I called it  localhostaddresses.dsn and put it into the same directory where Pragma lives.  The file is rather pathetic since after all that effort to create it, it contains only two lines of text:

[ODBC]
DRIVER=PostgreSQL

Now that you have this earth shattering dsn file and are back to the 'Select Data Source' window double click on the dsn file you created and you will get to the following window: 

Database Insert the name of the database you want to connect to.  With the PostgreSQL Administrator we created a database called 'Pragma Tutorial' so enter that name or whatever database name you created.

Server Since the server is on the same machine that runs Pragma, insert localhost, a PostgreSQL key word.

User name In our case we have only one user, postgres.

Port Leave the default, unless you changed it during the installation of PostgreSQL.

Password Even if you chose not to have a password, you must go to the edit field, leave the entry blank and hit 'return'.

 

You have finally reached the 'PostgreSQL Connect Dialog' which now states that you are connected.

In the dialog box you can now see the connect script and all the tables that the database 'Pragma Tutorial' contains.

This cumbersome procedure happens only when you connect for the first time to PostgreSQL.  Pragma 6 remembers the connect script in the Windows registry and the next time you connect the procedure is simplified.  Pragma 6 will stay connected as long as it is open or you go to the connect dialog and hit the disconnect button.  

If you want to access another database you disconnect from the one you are connected and repeat the whole procedure described above with the new database.

One word of caution.  The connect script will also remember your password, if you used any.  This can lead to a severe security breach if somebody else accesses your computer.

 

Exit the 'PostgreSQL Connect Dialog' and in the now active 'View SQL DATA' window enter your SQL SELECT query (in our case you can enter SELECT * FROM addresses) and you will see the requested information.

 

 

Select it and finally hit the 'View Data...' button.  Miracle of miracles, all the entries you made into the 'address' table will be shown.

Granted, the whole procedure to view the data for the first time is rather cumbersome, to say the least, but it conforms to the ODBC standards.  Proof is that even an old version of Pragma 5 can look at the created PostgreSQL data.

 

Connecting to a Database on a Network

To connect to a database on a network the procedure is not much different.

If you have connected to your machine (localhost) click on the New Connection button in the Connect Dialog until you get to an empty PostgreSQL Connection dialog, which you fill in the following way.  Remember that the dsn file is totally irrelevant and you can keep for all the connections the same one.

Database Insert the name of the database you want to connect to on the network.  With the PostgreSQL Administrator we created a database called 'PH Data' on the network machine so enter that name or whatever database name you created.

Server Since the server is on the network, insert the IP address of the machine you want to connect to.

User name In our case we still have only one user, postgres.

Port Leave the default, unless you changed it during the installation of PostgreSQL.

Password Enter your password.

If you entered all the data correctly, you will get 'Connected' in the Connect Dialog.

 

If you cannot connect, more than likely you did not authorize your machine to connect to the machine on the network.  Read the subchapter Accessing PostgreSQL on a Network with PGAdmin III of the PostgreSQL Installation chapter of the tutorial.

 

Be aware that in  these early versions Pragma 6 commits a security breach by saving your password (if any)  in the Windows registry!  This will change in the future.  You have been warned!
 
2005-11-30
logo logical.gif, lip_tec3.gif, header postgres.gif
t_tut_postgres p6 connect.htm