How To Connect PostgreSQL thru VB without DSN
How To Connect PostgreSQL thru VB without DSN
am 18.03.2006 14:26:52 von pragadheeswaran gopalakrishnan
------=_Part_3511_28454404.1142688412319
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: inline
SGksCgpJIHdhbnQgdG8ga25vdyBIb3cgVG8gQ29ubmVjdCAgUG9zdGdyZVNR TCB0aHJ1IFZCIHRo
cm91Z2hEU04tbGVzcwpjb25uZWN0aW9uLgoKSSB1c2VkIHRoZSBmb2xsb3dp bmcgc3ludGF4ClBy
aXZhdGUgU3ViIENvbm5lY3REQgpPbiBFcnJvciBHb1RvIEVICkRpbSBjIEFz IE5ldyBBRE9EQi5D
b25uZWN0aW9uCmMub3BlbiAiRFJJVkVSPXtQb3N0Z3JlU1FMfTtTRVJWRVI9 MjAwLjIwMC4yMDAu
MQo7cG9ydD01NDMyO0RBVEFCQVNFPU15REI7VUlEPXBvc3RncmVzO1BXRD1w b3N0Z3JlczsiCkV4
aXQgU3ViCkVIOgpNc2dib3ggRXJyLkRlc2NyaXB0aW9uLHZiY3JpdGljYWws IkVycm9yIEluZm8i
CkVuZCBTdWIKClRoZSAgSVAgYWRkcmVzcyBvZiB0aGUgbWFjaGluZSwgd2hl cmUgUG9zdGdyZVNR
TCBpcyBpbnN0YWxsZWQsIGlzCjIwMC4yMDAuMjAwLjEgIHdoaWNoIGkgbm90 ZWQgZnJvbSB0aGUg
TXluZXR3b3JrIHBsYWNlcyAtLS0+IHByb3BlcnRpZXMgLS0tPgpMb2NhbCBB cmVhIENvbm5lY3Rp
b24gLS0tPiBUQ1AvSVAgSW50ZXJuZXQgUHJvdG9jb2wgcHJvcGVydGllcy4K ClRoZSBvcGVyYXRp
bmcgc3lzdGVtIGluc3RhbGxlZCBpcyBXaW4tMjAwMAoKQnV0ICwgdGhlIGFi b3ZlIGNvZGUgZ2l2
ZXMgZXJyb3IgYXMgW01pY3Jvc29mdF1bT0RCQyBEcml2ZXIgTWFuYWdlcl0g RGF0YQpTb3VyY2Ug
bmFtZSBub3QgZm91bmQgb3IgZGVmYXVsdCBkcml2ZXIgbm90IHNwZWNpZmll ZC4KCkkgZ3Vlc3Mg
dGhlIHZhbHVlIGZvciB0aGUgU0VSVkVSIHBhcmFtZXRlciBpbiB0aGUgYWJv dmUgY29ubmVjdGlv
biBzdHJpbmcKY29kZSB3aWxsIGJlIHdyb25nLiBQbGVhc2UgZ3VpZGUgbWUu CgotLQpHLlByYWdh
ZGhlZXN3YXJhbgo=
------=_Part_3511_28454404.1142688412319
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: inline
SGksPGJyPgo8YnI+Ckkgd2FudCB0byBrbm93IEhvdyBUbyBDb25uZWN0Jm5i c3A7IFBvc3RncmVT
UUwgdGhydSBWQiB0aHJvdWdoRFNOLWxlc3MgY29ubmVjdGlvbi48YnI+Cjxz cGFuIHN0eWxlPSIi
IGlkPSJwb3N0Z3JlIj48c3BhbiBpZD0icG9zdGdyZXNxbCIgc3R5bGU9ImN1 cnNvcjogZGVmYXVs
dDsiPjxicj4KSSB1c2VkIHRoZSBmb2xsb3dpbmcgc3ludGF4PGJyPgo8c3Bh biBzdHlsZT0iY29s
b3I6IHJnYig1MSwgMTAyLCAyNTUpOyI+UHJpdmF0ZSBTdWIgQ29ubmVjdERC PC9zcGFuPjxiciBz
dHlsZT0iY29sb3I6IHJnYig1MSwgMTAyLCAyNTUpOyI+CjxzcGFuIHN0eWxl PSJjb2xvcjogcmdi
KDUxLCAxMDIsIDI1NSk7Ij5PbiBFcnJvciBHb1RvIEVIPC9zcGFuPjxiciBz dHlsZT0iY29sb3I6
IHJnYig1MSwgMTAyLCAyNTUpOyI+CjxzcGFuIHN0eWxlPSJjb2xvcjogcmdi KDUxLCAxMDIsIDI1
NSk7Ij5EaW0gYyBBcyBOZXcgQURPREIuQ29ubmVjdGlvbjwvc3Bhbj48YnIg c3R5bGU9ImNvbG9y
OiByZ2IoNTEsIDEwMiwgMjU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yI+Cjxi cj4KVGhlJm5ic3A7
IElQIGFkZHJlc3Mgb2YgdGhlIG1hY2hpbmUsIHdoZXJlIFBvc3RncmVTUUwg aXMgaW5zdGFsbGVk
LCBpcwo8YSBocmVmPSJodHRwOi8vMjAwLjIwMC4yMDAuMSI+MjAwLjIwMC4y MDAuMTwvYT4mbmJz
cDsgd2hpY2ggaSBub3RlZCBmcm9tIHRoZSBNeW5ldHdvcmsgcGxhY2VzIC0t LSZndDsKcHJvcGVy
dGllcyAtLS0mZ3Q7IExvY2FsIEFyZWEgQ29ubmVjdGlvbiAtLS0mZ3Q7IFRD UC9JUCBJbnRlcm5l
dApQcm90b2NvbCBwcm9wZXJ0aWVzLiA8YnI+Cjxicj4KVGhlIG9wZXJhdGlu ZyBzeXN0ZW0gaW5z
dGFsbGVkIGlzIFdpbi0yMDAwPGJyPgo8YnI+Cjwvc3Bhbj48L3NwYW4+QnV0 ICwgdGhlIGFib3Zl
IGNvZGUgZ2l2ZXMgZXJyb3IgYXMgW01pY3Jvc29mdF1bT0RCQyBEcml2ZXIg TWFuYWdlcl0gRGF0
YSBTb3VyY2UgbmFtZSBub3QgZm91bmQgb3IgZGVmYXVsdCBkcml2ZXIgbm90 IHNwZWNpZmllZC48
YnI+Cjxicj4KSSBndWVzcyB0aGUgdmFsdWUgZm9yIHRoZSBTRVJWRVIgcGFy YW1ldGVyIGluIHRo
ZSBhYm92ZSBjb25uZWN0aW9uIHN0cmluZyBjb2RlIHdpbGwgYmUgd3Jvbmcu IFBsZWFzZSBndWlk
ZSBtZS48YnIgY2xlYXI9ImFsbCI+PGJyPi0tIDxicj5HLlByYWdhZGhlZXN3 YXJhbjxicj4K
------=_Part_3511_28454404.1142688412319--
Re: How To Connect PostgreSQL thru VB without DSN
am 18.03.2006 23:17:45 von Greg Campbell
This is a multi-part message in MIME format.
--------------090907000802080609080303
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Your connection string looks fine, assuming that it is all really on one line.
Your error sounds like your Driver is not properly installed.
Troubleshooting:
1. In the ODBC Administrator, check the Drivers tab. Is "PostgreSQL" listed. (This corresponds to the
{PostgreSQL} in your connection string.
2. In registry check HKLM\SOFTWARE\ODBC\ODBCINST.INI\PostgreSQL -- There will be keys elaborating the
location of .dlls. Do those DLLs exist.
What version is your PostgreSQL server?
3. Check, does your server permit remote connections?
In postgresql.conf that TCPIP_SOCKET parameter in version up to 7.4 (I think) and parameter
listen_addreses in version 8+.
4. Does your PostgreSQL server permit the username and password your are trying to supply from your
location? Check pg_hba.conf settings.
Other checks (just for troubleshooting).
Does it work if you use "DSN=myDSNname" type connection string?
Can you connect with pgAdmin?
BTW. The connection string will take a FQDN (fully qualified domain name) -- if you have the means for DSN
translation. That is if you can successfully ping "mycomputer.mydomain.com" instead of 200.200.200.1,
that'll work too.
pragadheeswaran gopalakrishnan wrote:
> Hi,
>
> I want to know How To Connect PostgreSQL thru VB throughDSN-less
> connection.
>
> I used the following syntax
> Private Sub ConnectDB
> On Error GoTo EH
> Dim c As New ADODB.Connection
> c.open "DRIVER={PostgreSQL};SERVER=200.200.200.1
> ;port=5432;DATABASE=MyDB;UID=postgres;PWD=postgres;"
> Exit Sub
> EH:
> Msgbox Err.Description,vbcritical,"Error Info"
> End Sub
>
> The IP address of the machine, where PostgreSQL is installed, is
> 200.200.200.1 which i noted from the Mynetwork places ---> properties --->
> Local Area Connection ---> TCP/IP Internet Protocol properties.
>
> The operating system installed is Win-2000
>
> But , the above code gives error as [Microsoft][ODBC Driver Manager] Data
> Source name not found or default driver not specified.
>
> I guess the value for the SERVER parameter in the above connection string
> code will be wrong. Please guide me.
>
> --
> G.Pragadheeswaran
--------------090907000802080609080303
Content-Type: text/x-vcard; charset=utf-8;
name="greg.campbell.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="greg.campbell.vcf"
YmVnaW46dmNhcmQNCmZuOkdyZWcgQ2FtcGJlbGwNCm46Q2FtcGJlbGw7R3Jl
Zw0Kb3JnOk1pY2hlbGluIE5vcnRoIEFtZXJpY2EgLSBVUzUgTGV4aW5ndG9u
O0VORy1BU0UNCmVtYWlsO2ludGVybmV0OmdyZWcuY2FtcGJlbGxAdXMubWlj
aGVsaW4uY29tDQp0aXRsZTpBU0UgU3lzdGVtcyBFbmdpbmVlcg0KdGVsO3dv
cms6ODAzLTk1MS01NTYxL3g3NTU2MQ0KeC1tb3ppbGxhLWh0bWw6RkFMU0UN
CnZlcnNpb246Mi4xDQplbmQ6dmNhcmQNCg0K
--------------090907000802080609080303
Content-Type: text/plain
Content-Disposition: inline
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster
--------------090907000802080609080303--
Re: How To Connect PostgreSQL thru VB without DSN
am 20.03.2006 15:55:40 von Greg Campbell
This is a multi-part message in MIME format.
--------------080608070604070804000306
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
1. One thing at a time. Eliminate the section where you try to put data into the database. Does the
connection work. Do you get to the msgbox "Connection Message"?
2. Your pg_hba.conf host sections -- I hope you realize those are the addresses of your clients, so your
VB work station would have to have an I.P. of 200.200.200.something.
3. A normal PG problem would throw an error, which would show up as a message box, but VB would not crash
and close -- but your application will if it doesn't catch and handle errors. VB crashing indicates a more
gross error -- bad VB installation, missing References, code that's just wrong, etc.
4. The rsFriends seems to be missing a declaration and instantiation.
eg.
Dim rsFriends as ADODB.Recordset
Set rsFriends = new ADODB.Recordset
(Dim x as new Object -- is considered a somewhat sloppier form,
because it does not match the Set x= Nothing)
But as my first words indicate, don't worry about INSERTS or SELECTS until you are sure Connect will work.
5. Once you get the connect with the DSN, work on the DSN-less connect with the "Driver=..." string.
pragadheeswaran gopalakrishnan wrote:
>>4. Does your PostgreSQL server permit the username and password your are
>>trying to supply from your
>>location? Check pg_hba.conf settings.
>>
>>
>>
>
> Hi! Campbell, Thanks for replying,
>
> I will furnish some details for your kind notice.
>
> I am using VB to connect PostgreSQL database. It gets connected thru DSN
> based code.
>
> The following is a segment of my pg_hba.conf file
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++
> .
> .
> .
>
>
> # TYPE DATABASE USER CIDR-ADDRESS METHOD
>
> # IPv4 local connections:
> host all all 127.0.0.1/32 md5
> host all all 200.200.200.1 255.255.255.0
> md5
> # IPv6 local connections:
> host all all ::1/128 md5
> #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++
>
> When i run the code thru VB which is based on DSN leads to the following
> error
> "VB6.exe has generated errors and will be closed by Windows. You will need
> to restart
> the program."
>
> and VB itself gets closed after this error message
>
> my OS is WIN-2K
> my postgreSQL version is 8.1
>
>
> The code, which i used to connect pgsql is the following
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++
> Dim cCon As New ADODB.Connection, rsFriends As New ADODB.Recordset
> Private Sub Form_Load()
> ConnectDB
> End Sub
> Private Sub ConnectDB()
> On Error GoTo EH
>
>
> cCon.ConnectionString = "DSN=pgsdsn;" & _
> "UID=steve;" & _
> "PWD=king;" & _
> "Database=mydb"
>
> cCon.Open
> MsgBox "O.K.", vbInformation, "Connection Message"
> With rsFriends
> .Open "SELECT * FROM Friends", cCon, adOpenKeyset,
> adLockPessimistic 'Here only the error is generated
> .AddNew
> .Fields![FriNam] = InputBox("Enter the Friend Name")
> .Fields![SrlNum] = Val(InputBox("Enter the Serial Number"))
> .Fields![DOB] = InputBox("Enter the Date of Birth")
> .Fields![PhNo] = InputBox("Enter the Phone No:")
> .Update
> End With
> If rsFriends.State = adStateOpen Then rsFriends.Close
> Set rsFriends = Nothing
> MsgBox "O.K.", vbInformation, "Recordset Message"
> Exit Sub
> Exit Sub
> EH:
> MsgBox Err.Description, vbCritical, "Error Message"
> End Sub
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++
>
>
>
>
>
>
> The following, is the Error details written in LOG file under the LOG folder
> of POSTGRESQL
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++
>
> 2006-03-20 12:15:31 LOG: unexpected EOF on client connection
> 2006-03-20 12:15:37 LOG: could not receive data from client: No connection
> could be made because the target machine actively refused it.
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++
>
>
> Many Thanks in advance.
--------------080608070604070804000306
Content-Type: text/x-vcard; charset=utf-8;
name="greg.campbell.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="greg.campbell.vcf"
YmVnaW46dmNhcmQNCmZuOkdyZWcgQ2FtcGJlbGwNCm46Q2FtcGJlbGw7R3Jl
Zw0Kb3JnOk1pY2hlbGluIE5vcnRoIEFtZXJpY2EgLSBVUzUgTGV4aW5ndG9u
O0VORy1BU0UNCmVtYWlsO2ludGVybmV0OmdyZWcuY2FtcGJlbGxAdXMubWlj
aGVsaW4uY29tDQp0aXRsZTpBU0UgU3lzdGVtcyBFbmdpbmVlcg0KdGVsO3dv
cms6ODAzLTk1MS01NTYxL3g3NTU2MQ0KeC1tb3ppbGxhLWh0bWw6RkFMU0UN
CnZlcnNpb246Mi4xDQplbmQ6dmNhcmQNCg0K
--------------080608070604070804000306
Content-Type: text/plain
Content-Disposition: inline
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster
--------------080608070604070804000306--
Re: How To Connect PostgreSQL thru VB without DSN
am 20.03.2006 16:59:51 von Jamal Mazrui
This is a multi-part message in MIME format.
------_=_NextPart_001_01C64C37.539CFDE6
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
For the driver name in the connect string, try {PostgreSQL ANSI} or
{PostgreSQL Unicode}, instead of just {PostgreSQL}. I noticed that the
Windows ODBC administrator inserted this for the driver name.
Unfortunately, the new driver name was not documented in any of the
PostgreSQL documentation I found on ODBC, so it took me hours to debug
this problem.
=20
Regards,
Jamal
=20
=20
-----Original Message-----
From: pgsql-odbc-owner@postgresql.org
[mailto:pgsql-odbc-owner@postgresql.org] On Behalf Of pragadheeswaran
gopalakrishnan
Sent: Saturday, March 18, 2006 8:27 AM
To: pgsql-odbc@postgresql.org
Subject: [ODBC] How To Connect PostgreSQL thru VB without DSN
Hi,
I want to know How To Connect PostgreSQL thru VB throughDSN-less
connection.
I used the following syntax
Private Sub ConnectDB
On Error GoTo EH
Dim c As New ADODB.Connection
c.open "DRIVER=3D{PostgreSQL};SERVER=3D200.200.200.1
;port=3D5432;DATABASE=3DMyDB;UID=3Dpostgres;PWD=3Dpostgres;"
Exit Sub
EH:=20
Msgbox Err.Description,vbcritical,"Error Info"
End Sub
The IP address of the machine, where PostgreSQL is installed, is
200.200.200.1 which i noted from the Mynetwork places ---> properties
---> Local Area Connection ---> TCP/IP Internet Protocol properties.=20
The operating system installed is Win-2000
But , the above code gives error as [Microsoft][ODBC Driver Manager]
Data Source name not found or default driver not specified.
I guess the value for the SERVER parameter in the above connection
string code will be wrong. Please guide me.
--=20
G.Pragadheeswaran
------_=_NextPart_001_01C64C37.539CFDE6
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
charset=3Dus-ascii">
Message
size=3D2>For=20
the driver name in the connect string, try {PostgreSQL ANSI} or =
{PostgreSQL=20
Unicode}, instead of just {PostgreSQL}. I noticed that the Windows =
ODBC=20
administrator inserted this for the driver name. Unfortunately, =
the new=20
driver name was not documented in any of the PostgreSQL documentation I =
found on=20
ODBC, so it took me hours to debug this problem.
size=3D2>
size=3D2>Regards,
size=3D2>Jamal
size=3D2>
-----Original =
Message-----
From:=20
pgsql-odbc-owner@postgresql.org [mailto:pgsql-odbc-owner@postgresql.org] =
On=20
Behalf Of pragadheeswaran gopalakrishnan
Sent: Saturday, =
March 18,=20
2006 8:27 AM
To: pgsql-odbc@postgresql.org
Subject: =
[ODBC]=20
How To Connect PostgreSQL thru VB without =
DSN
Hi,
I=20
want to know How To Connect PostgreSQL thru VB throughDSN-less=20
connection.
style=3D"CURSOR: default">
I used the following syntax
style=3D"COLOR: rgb(51,102,255)">Private Sub ConnectDB
style=3D"COLOR: rgb(51,102,255)">
rgb(51,102,255)">On Error=20
GoTo EH
style=3D"COLOR: rgb(51,102,255)">Dim c As New ADODB.Connection
style=3D"COLOR: rgb(51,102,255)">
rgb(51,102,255)">c.open=20
"DRIVER=3D{PostgreSQL};SERVER=3D
style=3D"FONT-WEIGHT: bold; COLOR: rgb(255,0,0)">
href=3D"http://200.200.200.1">200.200.200.1
style=3D"COLOR: rgb(51,102,255)">=20
;port=3D5432;DATABASE=3DMyDB;UID=3Dpostgres;PWD=3Dpostgres;"
style=3D"COLOR: rgb(51,102,255)">
rgb(51,102,255)">Exit=20
Sub
style=3D"COLOR: rgb(51,102,255)">EH:
style=3D"COLOR: rgb(51,102,255)">
rgb(51,102,255)">Msgbox=20
Err.Description,vbcritical,"Error Info"
style=3D"COLOR: rgb(51,102,255)">
rgb(51,102,255)">End=20
Sub
The IP address =
of the=20
machine, where PostgreSQL is installed, is
href=3D"http://200.200.200.1">200.200.200.1 which i noted from =
the=20
Mynetwork places ---> properties ---> Local Area Connection =
---> TCP/IP=20
Internet Protocol properties.
The operating system installed is=20
Win-2000
But , the above code gives error as=20
[Microsoft][ODBC Driver Manager] Data Source name not found or default =
driver=20
not specified.
I guess the value for the SERVER parameter in the =
above=20
connection string code will be wrong. Please guide me.
clear=3Dall>
--=20
G.Pragadheeswaran
------_=_NextPart_001_01C64C37.539CFDE6--