Joined: 25 Jun 2016
|Posted: Sat Jun 25, 2016 12:59 am Post subject: PostgreSQL server via the ODBC drivers Hooked To VDO
Download server from here: http://www.enterprisedb.com/products-services-training/pgdownload
I'm using Windows 64 bit v9.5 server.
Download ODBC drivers from here: https://www.postgresql.org/ftp/odbc/versions/msi/
I'm using the 32 bit drivers for v9.5-300.
My machine is Windows 10.
Install the server. I set it up with no password and the user "postgres" and most default options. I created a simple test database using the PgAdmin III tool, but DON'T USE THE GRAPHICAL tool to do this. If you do, it will preserve the case of all created symbols, and you will have to double-quote all table and column names in your queries to get them to work; programmatically, that means escape-double-quote them (yuck!). Use scripts instead, in the interactive SQL tool, or run them from the console tool. Then your SQL will look "normal."
Install the ODBC drivers from the MSI package.
Go into Windows ODBC Administrator Control Panel applet and define a data source on your database. Mine is a User DSN. Point it to your server and your database name. Mine is set to ANSI.
Now that the plumbing is all hooked up, this VS2015 C# code will successfully operate:
virtConn = new VirtualConnection("DSN=PostgreSQL30; Database=myDatabaseName;", "postgres", "", -1, 5);
virtConn.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
virtRSet = new VirtualRecordset();
virtRSet.VirtualConnection = virtConn;
virtRSet.TableName = "myTable";
virtRSet.PrimaryKey = "myPkey";
virtRSet.SelectClause = "select * from myTable";
Alternatively, you can set these properties in the VS2015 designer once you drop both VDO components on your form. Then, any component with data bindings (like a Data Grid) will allow you to assign the VDO component as a data source (you will see it listed as you begin to set the property for the data source), and in the case of my data grid and this particular sample select clause, the grid will be filled with any data that is stored in the table, headed by column headings that match the column names and so forth.
-- Mike R.