Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
734 views
in Technique[技术] by (71.8m points)

python - Connecting to SQLServer 2005 with adodbapi

I'm very new to Python and I have Python 3.2 installed on a Win 7-32 workstation. Trying to connect to MSSQLServer 2005 Server using adodbapi-2.4.2.2, the latest update to that package.

The code/connection string looks like this:

conn = adodbapi.connect('Provider=SQLNCLI.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=XXX;Data Source=123.456.789');

From adodbapi I continually get the error (this is entire error message from Wing IDE shell):

Traceback (most recent call last): File "D:Program FilesWing IDE 4.0srcdebugserver_sandbox.py", line 2, in if name == 'main': File "D:Python32Libsite-packagesadodbapiadodbapi.py", line 298, in connect raise InterfaceError #Probably COM Error adodbapi.adodbapi.InterfaceError:

I can trace through the code and see the exception as it happens.

I also tried using conn strings with OLEDB provider and integrated Windows security, with same results.

All of these connection strings work fine from a UDL file on my workstation, and from SSMS, but fail with the same error in adodbapi.

How do I fix this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this connection string:

Initial Catalog=XXX; Data Source=<servername>\<SQL Instance name>; Provider=SQLOLEDB.1; Integrated Security=SSPI

Update

Umm ok. Looking at the source for adodbapi I would have to say that you are suffering a COM error. (yeah I know the traceback says that). But specifically with initialising the relevant COM objects.

This means that your connection string has nothing to do with the traceback. I think a good place to start would be to make sure that your copy of pythoncom is up-to-date.

It could be that win32com/pythoncom does not support Python 3K (3.0 onwards) yet, but after a minute of googleing I have not found anything useful on that, I'll leave it to you.

This code should run successfully when you have fixed your problem (and should fail at the moment).

import win32com.client
import pythoncom
pythoncom.CoInitialize()
win32com.client.Dispatch('ADODB.Connection')

Also any exception that code throws would be useful to help debug your problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...