使用adodbapi连接到SQLServer 2005 [英] Connecting to SQLServer 2005 with adodbapi

查看:137
本文介绍了使用adodbapi连接到SQLServer 2005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Python的新手,并且在Win 7-32工作站上安装了Python 3.2。尝试使用adodbapi-2.4.2.2(该程序包的最新更新)连接到MSSQLServer 2005 Server。

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');

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

从adodbapi中,我不断收到错误消息(这是来自Wing IDE Shell的全部错误消息):

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

Traceback(最近一次通话):
文件 D:\Program Files\Wing IDE 4.0\src\debug\tserver_sandbox.py ,第2行,如果 name ==' main ',则在
中:
文件 D:\Python32\Lib\site- package\adodbapi\adodbapi.py,行298,在连接
中引发InterfaceError#可能是COM错误
adodbapi.adodbapi.InterfaceError:

我可以跟踪代码并查看发生的异常。

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

我还尝试了将conn字符串与OLEDB提供程序和集成的Windows安全性,具有相同的结果。

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

所有这些连接字符串都可以从我工作站上的UDL文件以及SSMS中正常工作,但是由于adodbapi中的相同错误而失败。

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.

我该如何解决?

推荐答案

尝试以下连接字符串:

初始目录= XXX;数据源=<服务器名称> \\< SQL实例名称> ;; Provider = SQLOLEDB.1; Integrated Security = SSPI

好。查看adodbapi的源代码,我不得不说您遇到了COM错误。 (是的,我知道回溯就是这样)。但是特别是初始化相关的COM对象。

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.

这意味着您的连接字符串与回溯无关。我认为一个不错的起点是确保您的pythoncom副本是最新的。

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.

可能是win32com / pythoncom不支持Python 3K(3.0以后),但是经过一分钟的搜索,我还没有发现任何有用的东西,我会把它留给您。

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.

这篇关于使用adodbapi连接到SQLServer 2005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆