Need help with Visual Basic 6 and PostgreSQL

Need help with Visual Basic 6 and PostgreSQL

am 22.11.2007 03:36:57 von Finn Lassen






I am very new to ADODB, ODBC and SQL databases.



When I run the following which I wrote to populate tables (with data
from a Borland V database) , the Visual Basic Developer Interface
crashes with the following error signature (Windows XP):

AppName: vb6.exe     AppVer: 6.0.97.82     ModName: psqlodbc30a.dll

ModVer: 8.2.4.0     Offset: 00016edc

------------------------------------------------------------ ----------------  


    Dim dbOut As ADODB.Connection

    Dim rsOut As ADODB.Recordset

    Set dbOut = New ADODB.Connection

    Set rsOut = New ADODB.Recordset



    With dbOut

        .ConnectionString = "Driver={PostgreSQL
ANSI};Server=localhost;Port=5432;Database=postgres;Uid=user; Pwd=secret;"

        .Open

        With rsOut

            rsOut.Open """Contact1""", dbOut, adOpenDynamic,
adLockOptimistic, adCmdTable

            Do

                .AddNew

                For Each fld In .Fields

                    Debug.Print fld.name, fld.Type

                    Select Case fld.Type

                        Case 3 'integer (oid)

                        Case 200, 202 'Memo -- Text (ANSI: 200,
Unicode: 202)

                           fld.value = "Memo type text"

                        Case 133 'Date

                           fld.value = Date

                        Case Else

                           fld.value =
"FixedLengthStrings"                 

                    End Select

                Next fld

                .Update

                'Exit Loop code here

            Loop

            .Close

        End With

        .Close

    End With

    Set dbOut = Nothing

    Set rsOut = Nothing

------------------------------------------------------------ --------------------------------------------

Note: I had to add a "oid" column to the table or the rsOut.Open would
fail with "ERROR: column "oid" does not exist;".



It now crashes at the .Update statement.

Previously it managed to add 2 rows to the table.

Another oddity is when using the VB Visual Data Manager add-in to view
the database it will not list the Indexes for the Contact1 table.

It will list the Indexes for the Contact2 table which is not populated
nor been worked with.



Any suggestions on how proceed?

Do I have to configure the PostgreSQL ANSI driver somehow? If so, how?



Finn

-- 
Finn Lassen
Deputy CIO
Axiom
1805 Drew Street
Clearwater, Florida 33765
727-442-7774 voice
727-442-8344 fax




Re: Need help with Visual Basic 6 and PostgreSQL

am 22.11.2007 04:17:36 von Richard Broersma Jr

--- On Wed, 11/21/07, Finn Lassen wrote:
> It now crashes at the .Update statement.
> Any suggestions on how proceed?
> Do I have to configure the PostgreSQL ANSI driver somehow?

I would look at your PostgreSQL logs to see the exact crashing update statement that VB is sending to PostgreSQL to process (you may need to first turn on query logging in your postgresql.conf file and then restart your PostgreSQL service). Next I would try to manually run the listed update query in postgres' command line editor psql to see the error message that it generates. This will probably a very clear indication of what is wrong in your VB generated record-set update.

Also, give the how-to example for using ADO + ODBC + PG a try that comes with your ODBC installation help documentation?
it is found in this path on my computer:
C:\Program Files\PostgreSQL\8.2\doc\psqlODBC\howto-vb.html

Also, you may consider using the PostgreSQL Unicode ODBC driver over the ANSI driver since it supports a larger array of character sets.

I wish I could be of more help, but I've never really grown accustom to using Records sets to update or delete records. I've always manually crafted my own SQL statements that I've passed to the back-end server.

Also at the risk of getting my head bitten off by someone more knowledgeable that disagrees :-), it is a good practice to know your database schema design well enough to know the names of your tables and columns. It is also good practice to directly call out those column names in your code rather than simply guessing based on the field types.

Regards,
Richard Broersma Jr.

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Re: Need help with Visual Basic 6 and PostgreSQL

am 22.11.2007 04:34:01 von Paul Lambert

Finn Lassen wrote:
> I am very new to ADODB, ODBC and SQL databases.
>
> When I run the following which I wrote to populate tables (with data
> from a Borland V database) , the Visual Basic Developer Interface
> crashes with the following error signature (Windows XP):
> AppName: vb6.exe AppVer: 6.0.97.82 ModName: psqlodbc30a.dll
> ModVer: 8.2.4.0 Offset: 00016edc

I had perhaps a similar issue with VB6 earlir this year - program
crashing on doing a .Update, though mine was an access violation.

Refer to the thread here:
http://archives.postgresql.org/pgsql-odbc/2007-03/msg00045.p hp

My solution in the end was to drop using recordsets and the
addNew/Update methods to constructing an SQL INSERT/UPDATE/DELETE
statement of my own and running that through .Execute on the database
object instead.

I'd suggest turning on logging on the ODBC driver, running your program
until it crashes and then checking the contents of the mylog and
psqlodbc log in your root c directory. They might give a hint as to what
the problem is - perhaps some funny data being sent through.

--
Paul Lambert
Database Administrator
AutoLedgers - A Reynolds & Reynolds Company

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Re: Need help with Visual Basic 6 and PostgreSQL

am 23.11.2007 03:01:54 von Finn Lassen








On 21 Nov 07 10:17 PM, Richard Broersma Jr wrote:

type="cite">
--- On Wed, 11/21/07, Finn Lassen  wrote: 


It now crashes at the .Update statement.
Any suggestions on how proceed?
Do I have to configure the PostgreSQL ANSI driver somehow?



I would look at your PostgreSQL logs to see the exact crashing update statement that VB is sending to PostgreSQL to process (you may need to first turn on query logging in your postgresql.conf file and then restart your PostgreSQL service). Next I would try to manually run the listed update query in postgres' command line editor psql to see the error message that it generates. This will probably a very clear indication of what is wrong in your VB generated record-set update.


After rebooting the computer, it will make it through the first
iteration of the loop (successful .Update). Next time through I get
this (excerpt from log):

------------------------------

2007-11-22 20:21:14 ERROR:  column "" of relation "Contact1"
does not exist at character 40

2007-11-22 20:21:14 STATEMENT:  BEGIN;insert into "public"."Contact1" ("",
"Department", "TITLE", "SECR", "Phone1", "Phone2", "Phone3", "Fax",
"Ext1", "Ext2", "Ext3", "Ext4", "(", "Address2", "Address3", "City",
"State", "Zip", "Country", "Dear", "Source", "Key1", "Key2", "Key3",
"Key4", "Key5", "Status", "MERGECODES", "CreateBy", "Owner",
"LastUser", "LastDate", "LastTime", "VisibleTo", "RecID") values
(E'93100765018597400Bru'...

------------------------------

skipping over the first 4 field labels before "Department". (I hope the
quoted square box will post correctly here.)

During another run the "public" is replaced with the square box
(whatever that character is).

type="cite">

Also, give the how-to example for using ADO + ODBC + PG a try that comes with your ODBC installation help documentation?
it is found in this path on my computer:
C:\Program Files\PostgreSQL\8.2\doc\psqlODBC\howto-vb.html


Thanks. But that would eventually require an OBDC data source
definition on each work station, which I'd rather avoid....

type="cite">

Also, you may consider using the PostgreSQL Unicode ODBC driver over the ANSI driver since it supports a larger array of character sets.


I tried that. Same results.

type="cite">

I wish I could be of more help, but I've never really grown accustom to using Records sets to update or delete records. I've always manually crafted my own SQL statements that I've passed to the back-end server.


All I wanted to do was to quickly populate two tables with data from an
existing Borland database so I could run a speed comparison against
Access and MySQL. I tried the "COPY" SQL statement, but could not
easily get it to work because one of the source fields is a Memo field
containing all kinds of characters (but ANSI only). So I was
recommended to use the recordset method and not having to worry about
field delimiters.

type="cite">

Also at the risk of getting my head bitten off by someone more knowledgeable that disagrees :-), it is a good practice to know your database schema design well enough to know the names of your tables and columns. It is also good practice to directly call out those column names in your code rather than simply guessing based on the field types.


OK, I'll bite :)

Since I created the tables I'm intimately familiar with the schema.
Again, this was supposed to be a quick and dirty data import.



Obviously there is a bug on either the MS ADO or in the
psqlodbc30a.dll. Since the psqlodbc30a.dll is the one that produces the
exception ("Access violation, Context: PSQLODBC30A! 06f49797(),
06F49797   mov         edx,dword ptr [edi+0Ch]"), that DLL is the prime
suspect.



But I do appreciate you taking the time trying to help! Pointing me to
the log file really did help and I would think that whoever maintains
the psqlodbc30a.dll would be able to reproduce the error and fix the
bug. Meanwhile I'll try using MS DAO and a DSN connection.



Finn


Re: Need help with Visual Basic 6 and PostgreSQL

am 23.11.2007 15:39:19 von Richard Broersma Jr

--- On Thu, 11/22/07, Finn Lassen wrote:
> 2007-11-22 20:21:14 ERROR: column "" of relation
> "Contact1"
> does not exist at character 40
>
> 2007-11-22 20:21:14 STATEMENT: BEGIN;insert into
> "public"."Contact1" ("",
> "Ext4", "(", "Address2",

Does your table really have all of these field names? In addition to the "" field, I am suspicious of the "(" field. I am curious, if the ado recordset is seeing more fields than the table actually has. Since you weren't able to display the field that didn't exist in the table, you could possible determine if it is a ascii character by getting its charcode()(or something equivalent).

If you indeed find that your recordset does indeed see fields that do not exist in the table, then it is very likely that you have found a bug with the ODBC driver. It would help the developers to correct this problem if you were to submit a small test case that is able to reproduce the effects that you are seeing. It should include a sample database with sample table and it should include the VB codes that creates the recordset and then attempts to send an update to the table. They will probably want you to submit two of the ODBC drivers logs ( Mylog and Commlog ). These can be turned ON from your odbc drivers DSN user interface. (Just remember to turn off all odbc logging when your testing is done since odbc logging is a major performance killer.)

What version number of PostgreSQL are you running. What is the version number of the ODBC driver that you are using? Are they the latest released versions?



---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Re: Need help with Visual Basic 6 and PostgreSQL

am 23.11.2007 21:27:37 von Finn Lassen








On 23 Nov 07 9:39 AM, Richard Broersma Jr wrote:

type="cite">

Does your table really have all of these field names?


Yes. In fact there are 40 fields, the first four ("AccountNo",
"Company", "Contact" and "LastName") appear to be replaced by the
illegal character.  The illegal character is 0FH.



Since it goes through the loop OK the first time, it is obviously a
bug, and everything points to the ODBC driver.

type="cite">
  In addition to the "" field, I am suspicious of the "(" field.


There is no "(" field. The "(" is the SQL syntax for enumerating the
fields to be populated.
type="cite">
  I am curious, if the ado recordset is seeing more fields than the table actually has.


Nope. I checked that.

type="cite">
What version number of PostgreSQL are you running. What is the version number of the ODBC driver that you are using?  Are they the latest released versions?


pg_ctl.exe is version 8.2.5.7260
psqlodbc30a.dll is version 8.2.4.0

I downloaded them a couple of days ago, so I have to assume they are the latest.

How do I contact the developers?

Finn

P.S. Unfortunately I have already spent way more time on this than I can afford. This was supposed to be a quick evaluation to determine which database to replace the Borland with. I really should move on to looking at MySQL.


Re: Need help with Visual Basic 6 and PostgreSQL

am 23.11.2007 22:17:33 von Richard Broersma Jr

--- On Fri, 11/23/07, Finn Lassen wrote:
> There is no "(" field. The "(" is the
> SQL syntax for enumerating the
> fields to be populated.

>> 2007-11-22 20:21:14 STATEMENT: BEGIN;insert into "public"."Contact1" ("", "Department", ..., "(", ... ) values (E'93100765018597400Bru'...

Actually if you've noticed from this insert statement that you've previously posted, "(" is listed as a column name for data to be inserted. This must be caused by either the ODBC or ADO driver is telling PostgreSQL to insert data into a column that doesn't really exist. My gut feeling is that this shouldn't be a problem caused by the ODBC driver hence my suggest to specifically call out the column names of your table when you assign values to your fields.

> P.S. Unfortunately I have already spent way more time on
> this than I can afford. This was supposed to be a quick
> evaluation to determine which database to replace the
> Borland with. I really should move on to looking at MySQL.

No arguments from me on this point. MySQL is a very good RDBMS also, and depending upon your needs it should work out well for you. But if you later find that MySQL's features to not adequately satisfy some of you core development needs you could always give PostgreSQL a second try later on.

Regarding getting in touch with the developers, some of the ODBC developers subscribe to this mailing list. It could be that developers haven't had an opportunity to responded since this is a holiday weekend and may be unavailable.

However, the ODBC project has an official web-page for developers and bug reporting.
http://pgfoundry.org/projects/psqlodbc/
http://pgfoundry.org/tracker/?func=add&group_id=1000125&atid =538

Also, 3rd party vendor (Command Prompt) has developed their own ODBC driver that is supposed to have a more aggressive data caching mechanism. I haven't used it since the Official ODBC driver has worked so well in my case. You could see if this driver produces different results.

https://projects.commandprompt.com/public/odbcng/wiki/Downlo ads

They also have a mailing list dedicated to this driver:
http://lists.commandprompt.com/mailman/listinfo/odbcng

Regards,
Richard Broersma Jr.


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Re: Need help with Visual Basic 6 and PostgreSQL

am 24.11.2007 00:41:45 von Finn Lassen

A basic question:
In a connection string, if you only specify a driver name ("PostgreSQL
ANSI"), instead of a DSN configured with the ODBC Data Source
Administrator, do any configuration changes made with the ODBC Data
Source Administrator affect the driver itself?
In other words, does registering an ODBC driver automatically make it
subject to any configurations made with ODBC Data Source Administrator?

I still don't understand the:
"ERROR: Column "oid" does not exist;"
I get when executing the " rsOut.Open ..." statement below.
Can the ODBC driver only handle tables with oid columns?

Dim cn As ADODB.Connection
Dim rsOut As ADODB.Recordset
Set cn = New ADODB.Connection
Set rsOut = New ADODB.Recordset
With cn
.ConnectionString = "Driver={PostgreSQL
ANSI};Server=localhost;Port=5432;Database=postgres;Uid=user; Pwd=secret;"
.Open
With rsOut
rsOut.Open """Contact1""", dbOut, adOpenDynamic,
adLockOptimistic, adCmdTable

Finn


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Re: Need help with Visual Basic 6 and PostgreSQL

am 24.11.2007 01:05:25 von Richard Broersma Jr

--- On Fri, 11/23/07, Finn Lassen wrote:
> In a connection string, if you only specify a driver name
> ("PostgreSQL
> ANSI"), instead of a DSN configured with the ODBC Data
> Source
> Administrator, do any configuration changes made with the
> ODBC Data
> Source Administrator affect the driver itself?

I am not sure, but I do know what my connection string gets stored as when I used a system DSN:

DSN=myDSNname;DATABASE=myDatabase;SERVER=myServer;PORT=5432; UID=myUserName;PWD=myPassWord;CA=d;A6=;A7=100;A8=4096;B0=254 ;B1=8190;BI=0;C2=dd_;;CX=1b103bb;A1=7.4-1

Maybe in you augmented your connection string using these values, it might help?

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Re: Need help with Visual Basic 6 and PostgreSQL

am 24.11.2007 01:08:50 von me

> In other words, does registering an ODBC driver automatically make it
> subject to any configurations made with ODBC Data Source Administrator?

as i understand it: partly. i.e. the connection pooling configuration
options you specify in the ODBC Data Source Administrator is a global
setting.

> I still don't understand the:
> "ERROR: Column "oid" does not exist;"
> I get when executing the " rsOut.Open ..." statement below.
> Can the ODBC driver only handle tables with oid columns?

no. i have no problems accessing a DB with and without oids using this
connection string:

Driver={PostgreSQL
UNICODE};Server=yourserver;Port=5432;Database=yourdb;UID=you ruser;pwd=yourpassword;TrueIsMinus1=1;BoolsAsChar=0;TextAsLo ngVarchar=1;UseDeclareFetch=0

> rsOut.Open """Contact1""", dbOut, adOpenDynamic,
> adLockOptimistic, adCmdTable

try this:

rsOut.Open "SELECT * FROM ""Contact1""", dbOut, adOpenDynamic,
adLockOptimistic

the problem might be the adCmdTable recordset type.

regards,
thomas


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Re: Need help with Visual Basic 6 and PostgreSQL

am 24.11.2007 01:27:03 von Richard Broersma Jr

--- On Fri, 11/23/07, Finn Lassen wrote:
> "ERROR: Column "oid" does not exist;"
> I get when executing the " rsOut.Open ..."
> statement below.

Here are some OID setting from ODBC driver manual:
....
OID Options:

Show Column: Includes the OID in SQLColumns. This is good for using as a unique identifier to update records if no good key exists OR if the key has many parts, which blows up the backend.

Fake Index: This option fakes a unique index on OID. This is useful when there is not a real unique index on OID and for apps which can't ask what the unique identifier should be (i.e, Access 2.0).
....

Perhaps the odbc driver defaults to showing ODBC column. In postgresql versions < 8.0 it was the default for every table to be given an OID (basically every row in any and all tables had a unique number that identified it). However, as of postgresql 8.0, OID columns are no longer added to all table by default. This could be causing the problem since the ODBC driver may be trying to select the OID column from your table even though it doesn't actually exist.

I will look for the ODBC documention that describes that settings that you can pass to the ODBC driver in the connection string.

Regards,
Richard Broersma Jr.

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Re: Need help with Visual Basic 6 and PostgreSQL

am 24.11.2007 01:50:19 von Richard Broersma Jr

--- On Fri, 11/23/07, Richard Broersma Jr <rabroersma@yahoo.com> wrote:


From the ODBC driver documentation,


here is the list of parameters that you can pass to the driver.


How to specify as a connection option











































































































































































Definition Keyword Abbreviation
Data source description Description Nothing
Name of Server Servername Nothing
Postmaster listening port Port Nothing
User Name Username Nothing
Password Password Nothing
Debug flag Debug B2
Fetch Max Count Fetch A7
Socket buffer size Socket A8
Database is read only ReadOnly A0
Communication to backend logging CommLog B3
PostgreSQL backend protocol Protocol A1
Backend enetic optimizer Optimizer B4
Keyset query optimization Ksqo B5
Send tobackend on connection ConnSettings A6
Recognize unique indexes UniqueIndex Nothing
Unknownresult set sizes UnknownSizes A9
Cancel as FreeStmt CancelAsFreeStmt C1
Use Declare/Fetch cursors UseDeclareFetch B6
Text as LongVarchar TextAsLongVarchar B7
Unknowns as LongVarchar UnknownsAsLongVarchar B8
Bools as Char BoolsAsChar B9
Max Varchar size MaxVarcharSize B0
Max LongVarchar size MaxLongVarcharSize B1
Fakes a unique index on OID FakeOidIndex A2
Includes the OID in SQLColumns ShowOidColumn A3
Row Versioning RowVersioning A4
Show SystemTables ShowSystemTables A5
Parse Statements Parse C0
SysTable Prefixes ExtraSysTablePrefixes C2
Disallow Premature DisallowPremature C3
Updateable Cursors UpdatableCursors C4
LF <-> CR/LF conversion LFConversion C5
True is -1 TrueIsMinus1 C6
Datatype to report int8 columns as BI Nothing
Bytea as LongVarBinary ByteaAsLongVarBinary C7
Use serverside prepare UseServerSidePrepare C8
Lower case identifier LowerCaseIdentifier C9
SSL mode SSLmode CA
Extra options AB Nothing
Abbreviate(simple setup of a recommendation value) CX Nothing

Re: Need help with Visual Basic 6 and PostgreSQL

am 24.11.2007 02:55:46 von Finn Lassen

Thanks for all your help!

I finally broke down and dropped the table and recreated it WITH OID.
Now everything works, even with these simple strings:
.ConnectionString = "Driver={PostgreSQL ANSI};Server=localhost;Port=5432;Database=postgres;Uid=user; Pwd=secret,B1=128000"
rsOut.Open """Contact1""", dbOut, adOpenDynamic, adLockOptimistic, adCmdTable

I don't understand the difference between "LongVarchar" and "Varchar", but I have to use B1 whether I use the ANSI or UNICODE driver.
(Source content of the memo field I put into text data type can be more than 64K, so I choose 128000. The default is 8196, so it has to be increased.)

Conclusion: Version 8.2.4.0 of psqlodbc30a.dll and psqlodbc30w.dll require tables WITH OID.
(The "OID Options, Show column" -- and presumably "ShowOidColumn" -- has no effect.)

Finn



--
Finn Lassen
Deputy CIO
Axiom
1805 Drew Street
Clearwater, Florida 33765
727-442-7774 voice
727-442-8344 fax
dcio@AxiomInt.com
www.AxiomInt.com



---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Re: Need help with Visual Basic 6 and PostgreSQL

am 24.11.2007 03:09:23 von Richard Broersma Jr

--- On Fri, 11/23/07, Finn Lassen wrote:
> I don't understand the difference between "LongVarchar" and
> "Varchar",
> but I have to use B1 whether I use the ANSI or UNICODE driver.
> (Content of the memo field I put into text data type can be more than
> 64K, so I choose 128000. The default is 8196, so it has to be increased.)

For what it is worth, Postgresql has a 1 Gb limit on the size of a text field. So if you know that you ascii chars are 8 bits, then you should be able to store a little over 134,000,000 characters.


> Conclusion: Version 8.2.4.0 of psqlodbc30a.dll and psqlodbc30w.dll
> require tables WITH OID.
> (The "OID Options, Show column" -- and presumably
> "ShowOidColumn" -- has
> no effect.)

I will try to spend some time to play with ADO record sets without using a DSN to see what happens and see with I can come up with. But in the mean time at least you can perform your test comparison.

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Re: Need help with Visual Basic 6 and PostgreSQL

am 24.11.2007 03:25:39 von Tom Lane

Richard Broersma Jr writes:
> For what it is worth, Postgresql has a 1 Gb limit on the size of a text field. So if you know that you ascii chars are 8 bits, then you should be able to store a little over 134,000,000 characters.

Uh, the hard limit is 1 gigabyte, not 1 gigabit.

(Whether you can approach the limit with reasonable performance is
another question ... I wouldn't try it in a 32-bit machine, for sure.)

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Re: Need help with Visual Basic 6 and PostgreSQL

am 24.11.2007 04:43:48 von Richard Broersma Jr

--- On Fri, 11/23/07, Tom Lane wrote:
> Uh, the hard limit is 1 gigabyte, not 1 gigabit.
Thanks for the clarification Tom.

Regards,
Richard

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly