Thursday, January 31. 2008Using MS Access with PostgreSQLPrinter FriendlyRecommended Books: Access 2007 - The Missing Manual
Access 2007 for Dummies Access 2007 VBA Programming for Dummies
Comments
Display comments as
(Linear | Threaded)
Here is one other point about Access and ODBC linked booleans:
It seems that access sees ODBC nulls as false. When Access tries to update a field with a boolean null, the update will fail since ACCESS uses all of the table's old column values in the where clause of an update statement: WHERE ... AND boolean_field = 'false'::boolean AND ... However, since boolean_field actually is null the update fails.
Hi there,
I found your article very useful, it helped me a lot migrating my MS Access-backend to a real database. However, there are some tricky problems I am facing now: some records are locked when I am (or someone else is) trying to edit them, whereby Access tells me that another user has been edited the record, which is why my changes cannot be saved. However, when I try to edit the same record with pgadmin (or funnily enough, with an updateble query in Access) I can edit anything I want. Do have some hint for me what the problem might be? thanks in advance, Chris
Haven't come across this particular problem in PostgreSQL, but I have with linked tables to SQL Server where by to resolve I had to put in SQL Server's native timestamp (which is not a timestamp) field in there.
Take a look at Mike' suggestion -- he enabled Row Versioning and that seemed to solve his write conflicts - which is check box on the second page of ODBC config. If you are using file dsn, I think you will need to relink your tables. Hope that helps, Regina
Thanks for your advice, I will try to adapt the File DSN configuration. One thing I don't understand: I have migrated my postgres-DB to another server (identical structure and data), and there I am allowed to edit the records which I'm not allowed to in the old one. I have just checked the DSN configuration, and they are also identical. Do you happen to have any idea what that might be?
Hi again,
I have now tried to activate the row versioning, and now it works, thanks for your help! Chris
Do you have any boolean columns in the write-conflict table? If so, instead using row versioning, make sure the boolean fields are never null, e.g. by issuing
ALTER TABLE your_table ALTER COLUMN your_boolean column SET DEFAULT FALSE; UPDATE your_table SET your_boolean_column = FALSE WHERE your_boolean_column IS NULL; Without row versioning enabled MS Access/ODBC driver doesn't use any highly-sophisticated versioning, but simply tries to find a record with exactly the same field values as the updated row (i.e. it issues sth like UPDATE SET ... WHERE col1=current_col1_value AND col2=current_col2_value ... AND colN = current_colN_value). If the record isn't found, access shows write-conflict message. If your table doesn't contain any boolean columns you may look at the communication logs (enable it in the odbc configuration and relink the faulty table) to see why the update query issued by odbc/access doesn't find any record. Row versioning is an inferior choice because it adds the xmin column to tables and the users shouldn't really mess with values in that column...
It's a shame Access hasn't been updated since the 7.4 series, which has long, white whiskers on it.
I always found it strange that the PostgreSQL ODBC driver says 7.4 on it even though well it obviously works with 8.0 versions and has been continuely updated. I think it is mostly a labeling issue on the ODBC driver but would be good PR to say 7.4-8.3 or something like that.
As far as functionality, I don't think it would make too much of a difference where ODBC is concerned.
A BIG thank you for this article. It saved me a ton of time while doing a migration from Access to Postgres
I think it's important to note that "Text as LongVarChar" should be Disabled.
I've had nothing but trouble with the "Bools as Char" option. If I uncheck it, as indicated here, I get the unpopular "Write Conflict" behaviour that I've seen elsewhere. It is fine with "Bool as Char" selected.
Does anyone else have this issue with Access 2000 and the 8.03.02.00 Unicode driver (or any other combination)? It could be a bug, but I'm not sure.
After much experimenting, I'll now highly recommend enabling the "Row Versioning" option. I've had some additional "Write Conflict" problems that are different than described above, and these issues all seem to be magically resolved in MS Access by enabling Row Versioning. I'd love to know what it is someday.
The .dsn file in C:\Program Files\Common Files\ODBC\Data Sources only has one entry namely:
[ODBC] DRIVER=PostgreSQL ANSI I wish to change the port that is used to access the database. Any ideas why the dsn file is missing its required entries. Using access 2002 SP3 .
Add to it
PORT=5433 or whatever your port is. Might be better to just create another DSN though. I think what you are looking at is a default DSN. Its best not to use that one. All the parameters not specified end up taking their defaults so the PORT would be 5432 when not specified. You can simply createa new DSN by copying and pasting from that one or our example and adding in any extra things.
I experienced the following issue: Upon inserting a new row Access then displays every field in the row as "#Deleted". However the insert has not failed, requerying the table displays the newly inserted row.
This was due to the fact that after every insert operation access performs a query to verify the insert. It attempts the verification twice, once using a SELECT based on the primary key, if that fails it performs a SELECT using every other field it inserted in the row. See: http://support.microsoft.com/kb/128809 My issue arose because the primary key in the table is a sequence and access doesn't by default know the next value (it's generated by a trigger upon insert) so the first verification attempt failed. The second verification also failed in my case as a different trigger on my table validates and changes one of the fields before insert (so the value in that field doesn't match the value Access used in the insert command). I fixed this problem by writing a vba module that fetches the next sequence value from postgres with a passthrough query so Access can set the primay key directly rather than relying on the upon insert trigger. I followed the example on this website (it's for oracle but can very easily be modified for postgres): http://www.techonthenet.com/access/queries/passthrough2.php
Inserting an Image!
Hi, I am using Ms Access as a front end to my Postgres DB. This tutorial is very useful. One important thing not discussed here is how to insert/load images in a table. The BLOB or bytea type is somehow not recognized or incompatible with MS Access Object OLE. The column declared as BLOB in Postgres appear as binary in Ms Access. Thanks for any advice.
Yea this tutorial is really helpfull. Thanks.
I have managed to create the ODBC link succesfully but my tables do not display in the list(for selection), i have checked priviledges and access is public, so what is wrong? Thanks Jepola
Jepola,
You don't see any tables at all when you go to Get external data -> Linked Tables Which version of Access are you using?
Using ESF Database Migration Toolkit. It can migrating ms access to postgresql or back in 3 simple wizard steps without writing any sql script.
http://www.easyfrom.net/
Thank you for the helpful article.
Any idea why I am receiving an error message for "connection time out" while following the export procedure from MS Access 2007 to postgres database on a remote server? while it works fine for a postgres installation on localhost. I basically want to export large amount of data from access 2007 to remote installation of postgres database. An advice will be highly appreciated.
Unfortunately for large amounts of data across a not so local network, Access kind of sucks. I think its because of the way it tries to manage transactions so it can roll back the insert.
What we usually do for datasets above say 100,000 records is export the data out of access in CSV format and then use the built in psql or SQL in PostgreSQL to import the data. An easy step so you don't need to create the structure is to create a query that has a where clause such that you get no data and then export that. That will give you the structure in PostgreSQL. Then use the csv dump to import the data. We have some examples of csv import on our cheatsheet I believe: http://www.postgresonline.com/journal/archives/177-PostgreSQL-9.0-Cheat-Sheet-Overview.html
Thank you for the reply. Being newbee, but an enthusiastic one, I want to know what is my mistake. Therefore to test this method for postgres on a remote ISP, I've created a new db with 1 table and 2 rows. Even then I get the same error "odbc call failed could not connect to the server error #101". I tried to use Access 2003 & Access 2007, no difference.
I suspect that I may be putting wrong Server while creating the file dsn in Access. After login into the ISP via web, If I go to my databases section and select this pg database, it shows me some info. I saw a field called External Hostname = postgres32.xyzISP.net. I tried this as Server name but got above mentioned error. Then I went to phpPgAdmin page of my db and saw the IP address of database server and using it as Server in dsn creation, does not help either. I tried to create Pass through query by giving in all the parameters but only the eror message changed to "ODBC--Connection to '{Postgres ANSI}givenIPaddress' failed". Any suggestion?
I'm guessing your pg_hba.conf file is not set right on your postgreSQL server to allow connection from your local pc or there is a firewall in place on your ISP preventing port 5432 from being accessed directly. If you can't access the server from your local pgAdmin III then you wouldn't be able to either from MS Access. If you can via pgAdmin, then the pg_hba.conf is set up fine.
You can either change your pg_hba.conf if that is the problem or setup an ssh tunnel. http://www.postgresonline.com/journal/archives/38-PuTTY-for-SSH-Tunneling-to-PostgreSQL-Server.html
It is not clear fron this article whether such an Access connection can be used for a data entry/edit tool, or just as a query tool.
Is it possible to connect to a Postgres DB using Access via ODBC as a data entry/edit tool?
Brent,
Yes. In fact we have apps that do just that. The thing to be careful of is make sure to check the Row Version checkbox otherwise you sometimes get weird errors like record has already been edited. The only problem is it can't make sense of specialty types like geometry, hstore etc so shows them as text (which for hstore is fine). You can only do PostgreSQL specific SQL via passthrus or build the logic in a view and link the view as a table in Access. For simple edits appends etc its great, forms reports etc. its great.
Great tute, thanks. I got the latest ODBC driver and installed it. I successfully created a connection with Access 2007 creating a 2003 database on Win7 using your example DSN (I use a non-standard port) however, when I close the table and try to reopen it I get an ODBC error. It seems that it connects first time but never after the first time!! Any ideas?
when you link the table, make sure to choose -- Save Password. If you don't I think it just prompts for passwords for each table though not fails.
Shaun,
Which ODBC are you referring to? I've been using the ones here: http://www.postgresql.org/ftp/odbc/versions/msi/ Though I think we've been using the 9.0 series with our MS Access 2010 64-bit install and haven't run into issues.
Tx...I've tried this driver, but it doesn't appear under the drivers listed in Setup ODBC DataSource. The version 9 64Bit one does.....
http://wwwmaster.postgresql.org/download/mirrors-ftp/odbc/versions/msi/psqlodbc_08_04_0200.zip
right there is your problem. If you have a 64bit Office, you need to use the 64bit driver versions which end in x64. That one is the 32bit driver.
There isn't a 64-bit 8... on the site so you need to use a 64bit 9... one. Note 9.. driver will work fine for lower versions of PostgreSQL so don't get thrown off by the version number. http://ftp9.us.postgresql.org/pub/mirrors/postgresql/odbc/versions/msi/ So pick a -x64 one and you should be fine.
Tx. I tried it but get ODBC call failed:
The specified DSN contains an architecture mismatch between the Driver and Application (#0)
Where do you get that error? During install or when trying to create the DSN.
I assume when trying to create the DSN. How are you creating the DSN? You definitely running Office 64-bit right?
It seems a reboot of PC was needed - I'm now finding the ver 8 file and linked fine with it.
Its probably not 64bit Access... although can't find where to check it. Tx 4 the reply.
Creating the boolean operators as suggested here, triggers BUG #7758 [1] of PostgreSQL, i.e. the output of pg_dump is broken.
The workaround is described on PostgreSQL documentation [2]: omit the COMMUTATOR (NEGATOR) clause in the first operator that you define, and then provide one in the second operator's definition. [1]: http://www.postgresql.org/message-id/41ED3F5450C90F4D8381BC4D8DF6BBDC729C317D@EXCHANGESERVER.ikoffice.de [2]: http://www.postgresql.org/docs/9.2/static/xoper-optimization.html#AEN53307 |
Entry's LinksQuicksearchCalendar
Categories
Blog Administration |
FWTools GIS Toolkit is a freely available open source toolkit for Windows and Linux that can do more than GIS tricks. It is a precompiled bundle of Open Source GIS tools. The FW comes from the initials of Frank Warmerdam, the originator of the tool
Tracked: Feb 20, 15:22
What is PHP Gallery 2? PHP Gallery 2 is a web-based management system for storing pictures and other documents such as movies and flash files. While it is not designed for storing documents such as Microsoft Word or PDF, it serves as a simple storage c
Tracked: May 20, 03:08
Tracked: Oct 04, 18:28
Tracked: Feb 01, 06:02
Tracked: Jul 15, 05:52
Tracked: Jul 16, 09:17
Tracked: Sep 04, 00:21
Tracked: Aug 31, 17:58