Similarly to MySQL , PostgreSQL database has no straight-forward OLEDB plugin and there is need to either use scripting or ODBC to access to it. Here are 2 sample methods (there are also some 3rd party methods, but not tested by us):
- npgSQL in graphic form/server script. This one is for data representation. It is basically the same case as in MySQL. Just remember when installing npgSQL on Your machine to add it to GAC to have npgsql.dll in Your system assemblies instead of using just nuget.
Add references to Your graphic form script:
using Npgsql;
using System.Data;
Now draw a datagridview on Your graphic form, add a button, expose the datagridview to script and double-click on the button to create a click event inside the script.
All is left to do is to put Your PostgreSQL connector code behind the button_click event.
DataSet ds = new DataSet();
NpgsqlConnection conn = new NpgsqlConnection(“Server=localhost;Port=5432;User Id=postgres;Password=password;Database=MAPS;”);
try
{
conn.Open();
string sql = “SELECT “DT”, “Value1” FROM public.“MAPSTest””;
NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, conn);
da.Fill(ds);
dataGridView.DataSource = ds.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
conn.Close();
Done! Remember to properly address Your schemas and queries - it is little bit different from other databases.
-
ODBC in DBAccess this one is for logging/interaction with agents using DBAccess agent and ODBC connector. Now, remember that our software is 32-bit, hence it requires 32-bit ODBC connector and configured dns in 32-bit version of Your windows ODBC configurator.
Pick from the postgreSQL corresponding version to Your server and install it over.
Take a look at this screenshot of sample PostgreSQL configuration in DBAccess (I had to add “” qotation marks to Table and Column names even that from pick list it didn’t fill in these characters. Also, custom date formatting was required and that can be checked in Help topic about DBAccess agent - field format specifiers).