在Python脚本中不可能在本地数据库上建立Firebird连接

问题描述 投票:1回答:1

我可以使用Firebird ISQL工具(Firebird 3.0.4)通过以下命令连接到我的Firebird数据库:connect "C:\Documents\database.db" user 'USER' password 'PASSWORD';

[当我想在Python脚本(Windows10 64位的Python v3.7.7,在包括fdb v2.0.1甚至firebirdsql v1.1.3的虚拟环境中执行此操作时,我不能,而且我系统地得到了一个错误。

import fdb
con = fdb.connect(database="C:\Documents\database.db", user='USER' password='PASSWORD'')

DatabaseError:(''连接数据库时出错:\ n- SQLCODE: -902 \ n-无法完成对主机“ xnet:// Global \ FIREBIRD”的网络请求。',-902,335544721)

con = fdb.connect(host='localhost', database="D:\Documents\database.db", user= 'USER' password= 'PASSWORD'')

DatabaseError:(''连接数据库时出错:\ n- SQLCODE: -902 \ n-无法完成对主机“ localhost”的网络请求。\ n-无法建立连接。',-902,335544721)

con = fdb.connect(dsn="localhost:C:\Documents\database.db", user='USER' password='PASSWORD'')

DatabaseError:(''连接数据库时出错:\ n- SQLCODE: -902 \ n-无法完成对主机“ localhost”的网络请求。\ n-无法建立连接。',-902,335544721)

import firebirdsql
con = firebirdsql.connect(host='localhost', database="D:\Documents\database.db", user='USER' password='PASSWORD'')

如果您有任何想法,欢迎您,因为我被困住了。

python firebird fdb
1个回答
0
投票
要解决这个问题,您必须:

启动Firebird服务器

    如果要使用Firebird Embedded而不是Firebird Server,请将FDB指向提供Firebird Embedded的fbclient.dll
  • 第2点可以通过多种方式完成。在我的回答中,我假设使用安装在C:\Program Files\Firebird\Firebird-3.0.5.33220-0_x64中的Firebird 3。要指向嵌入式Firebird,您可以执行以下操作:
  • 将Firebird安装目录添加到PATH环境变量(确保它在

      之前%SystemRoot\System32/ C:\Windows\System32中列出)。在正常的Firebird安装中,fbclient.dll文件夹中安装了没有Firebird Embedded的System32,并且如果加载了该文件,则无法使用Firebird Embedded。
  • 使用fdb.load_api加载客户端库:fdb.load_api('C:/Program Files/Firebird/Firebird-3.0.5.33220-0_x64/fbclient.dll') 这需要在首次使用fdb.connect之前完成,否则将使用通过常规搜索路径找到的库]
  • 使用fb_library_name连接属性指定客户端库:
    con = fdb.connect(dsn='C:/path/to/yourdatabase.fdb', user='sysdba', password='masterkey', 
        fb_library_name='C:/Program Files/Firebird/Firebird-3.0.5.33220-0_x64/fbclient.dll')
    
    需要在使用FDB建立的第一个连接上指定此属性。尽管该属性的存在表明这是“每个连接”,但是FDB将始终使用加载的第一个客户端库(实质上,它的工作方式就像您在load_api之前调用了connect)。
  • [如果您使用的是Firebird 2.5或更早版本,则需要下载特定的Firebird 2.5 Embedded软件包,并指向其fbembed.dll而不是fbclient.dll。对于Firebird 2.5 Embedded,除非将其fbembed.dll重命名或复制到fbclient.dll,否则无法将其位置添加到路径中。
  • © www.soinside.com 2019 - 2024. All rights reserved.