473,581 Members | 2,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OCBC connection

I'm trying to make an odbc connection to postgresql which is on a server
using python.
Does anyone have a code snippet to make a basic connection with a select
query?

Sean
Sep 28 '07 #1
4 1688
On Sep 28, 9:57 am, "Sugrue, Sean" <Sean.Sug...@an alog.comwrote:
I'm trying to make an odbc connection to postgresql which is on a server
using python.
Does anyone have a code snippet to make a basic connection with a select
query?

Sean
Sean,

This appears to be what you're looking for:

http://www.devx.com/opensource/Article/29071

See also Python Database spec and module page:

http://www.python.org/topics/database/

Mike

Sep 28 '07 #2
ky******@gmail. com wrote:
On Sep 28, 9:57 am, "Sugrue, Sean" <Sean.Sug...@an alog.comwrote:
>I'm trying to make an odbc connection to postgresql which is on a server
using python.
Does anyone have a code snippet to make a basic connection with a select
query?

Sean

Sean,

This appears to be what you're looking for:

http://www.devx.com/opensource/Article/29071

See also Python Database spec and module page:

http://www.python.org/topics/database/
Mike:

This doesn't address the ODBC part of the inquiry. I was actually going
to respond saying I wasn't aware of an ODBC driver for PostgreSQL
(though I'd be surprised if there wasn't one).

Using the psycopg2 module, which is my preferred PostgreSQL interface
module, it's easy to answer:
>>curs = conn.cursor()
import psycopg2 as db
conn = db.connect(data base="pycon", user="username" ,
password="passw ord", host="localhost ", port=5432)
>>curs = conn.cursor()
curs.execute( "SELECT orgid, orgname FROM organization")
from pprint import pprint # just for neatness
pprint(curs.f etchall())
[(1, 'AB Strakt'),
(79, 'DevIS'),
...
(113, 'Test Organization'),
(19, 'Holden Web LLC')]
>>>
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

Sep 28 '07 #3
On Sep 28, 1:07 pm, Steve Holden <st...@holdenwe b.comwrote:
kyoso...@gmail. com wrote:
On Sep 28, 9:57 am, "Sugrue, Sean" <Sean.Sug...@an alog.comwrote:
I'm trying to make an odbc connection to postgresql which is on a server
using python.
Does anyone have a code snippet to make a basic connection with a select
query?
Sean
Sean,
This appears to be what you're looking for:
http://www.devx.com/opensource/Article/29071
See also Python Database spec and module page:
http://www.python.org/topics/database/

Mike:

This doesn't address the ODBC part of the inquiry. I was actually going
to respond saying I wasn't aware of an ODBC driver for PostgreSQL
(though I'd be surprised if there wasn't one).

Using the psycopg2 module, which is my preferred PostgreSQL interface
module, it's easy to answer:
>>curs = conn.cursor()
>>import psycopg2 as db
>>conn = db.connect(data base="pycon", user="username" ,
password="passw ord", host="localhost ", port=5432)
>>curs = conn.cursor()
>>curs.execute( "SELECT orgid, orgname FROM organization")
>>from pprint import pprint # just for neatness
>>pprint(curs.f etchall())
[(1, 'AB Strakt'),
(79, 'DevIS'),
...
(113, 'Test Organization'),
(19, 'Holden Web LLC')]
>>>

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline
Whoops! I almost posted some code using the adodb or the odbc module,
which is what I would have probably used, but I figured I'd take a
look and see if there was a postgres module available. I'm not seeing
any basic differences between your code and the code I linked to
though...except that if I ran your first line of code, I would get an
exception as "conn" hasn't been defined yet.

Whatever. I apologize for being misleading(?)

Mike

Sep 28 '07 #4
ky******@gmail. com wrote:
[...]
>>
> >>curs = conn.cursor()
import psycopg2 as db
conn = db.connect(data base="pycon", user="username" ,
password="passw ord", host="localhost ", port=5432)
> >>curs = conn.cursor()
curs.execute( "SELECT orgid, orgname FROM organization")
from pprint import pprint # just for neatness
pprint(curs.f etchall())
[(1, 'AB Strakt'),
(79, 'DevIS'),
...
(113, 'Test Organization'),
(19, 'Holden Web LLC')]
> >>>
Whoops! I almost posted some code using the adodb or the odbc module,
which is what I would have probably used, but I figured I'd take a
look and see if there was a postgres module available. I'm not seeing
any basic differences between your code and the code I linked to
though...except that if I ran your first line of code, I would get an
exception as "conn" hasn't been defined yet.

Whatever. I apologize for being misleading(?)
I screwed up anyway - the first line shouldn't have been included.

But perhaps Sean could enlighten us as to whether ODBC is really a
requirement, or simply the first solution that he thought of. I don't
know why one would *require* ODBC.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

Sep 28 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3915
by: G-Fit | last post by:
Hello group, I have several servers hosting SQL databases. On each of them, I have several databases. All those databases have the same structure (even those on different servers), only the data changes. I made a winforms application that allows me to manage those databases easily, and used several SqlDataAdapter to achieve this, all of...
11
2419
by: pradeep_TP | last post by:
Hi all, I have a few questions that I have been wanting to ask for long. These are all related to ADO.net and specifically to conenction to database. 1) If I have opened a connection to a database through Connection.open() method, and I do not use Connection.close() method, will garbage collector collect the connection object just because...
6
2338
by: Chris Szabo | last post by:
I've created a data access layer for a .NET web application. I'm using C# and framework 1.1. I'm getting an error from time to time when I close a connection saying: System.InvalidOperationException: A connection pooling error has occurred. It doesn't happen each time, the exception is thrown randomly. The big problem is that the...
18
3222
by: Rob Nicholson | last post by:
We're getting an occasional occurrence of the following error when two users try and open the same record in our ASP.NET app: "There is already an open DataReader associated with this Connection which must be closed first." As suggested, I was closing the connection in the Finally part of the outer Try but I wasn't closing the data reader...
35
11375
by: Eric Sabine | last post by:
In my Finally block, I was using cn.close (where cn is an ADO.NET connection object, SQLConnection to be exact) and then I came across the following in some microsoft code. If Not cn Is Nothing Then CType(cn, IDisposable).Dispose() End If I have to admit, I'm not sure what happens here. Will someone explain this line of code (the...
3
10285
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database I use System.Data.Common.DBConnection and .DBCommand. How can I keep aware from connection losses (network not availeable, db-server not...
20
3257
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how many connection has been used ? 2. If the maximum pool size has been reached, what happens when I call the method Open to open the connection ? Will I...
0
960
by: Sugrue, Sean | last post by:
Is this the right email list to be on for asking rather elementary python questions? If not do you have a suggestion Sean -----Original Message----- From: python-list-bounces+sean.sugrue=analog.com@python.org On Behalf Of Sugrue, Sean
0
7788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8299
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5355
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3813
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1397
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1127
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.