繁体   English   中英

为什么我不能在ubuntu 12.04中将python连接到firebird?

[英]why can't I connect python to firebird in ubuntu 12.04?

嗨,我也是python和firebird的新手,我的问题是我正在尝试将python程序连接到firebird中的数据库,我已经安装了firebird(当前位于/ opt / firebird上),我已经创建了数据库(测试.fdb)与表格(在firebird中正常工作)

create table languages
(
  name               varchar(20),
  year_released      integer
);

insert into languages (name, year_released) values ('C',        1972);
insert into languages (name, year_released) values ('Python',   1991);

但是当我尝试在pydev中运行时会出现问题。

import fdb

con = fdb.connect(dsn="/tmp/test.fdb", user="fernando", password="root")

# Create a Cursor object that operates in the context of Connection con:
cur = con.cursor()

# Execute the SELECT statement:
cur.execute("select * from languages")

# Retrieve all rows as a sequence and print that sequence:
print cur.fetchall()

http://www.firebirdsql.org/file/documentation/drivers_documentation/python/fdb/getting-started.html

databse的当前位置在/ tmp上,我使用的是从此处下载的fdb: https ://pypi.python.org/pypi/fdb/并与pip一起安装我也在pydev properties-> pydev pythonpath中使用并添加了文件夹fdb(到目前为止到目前为止似乎没有错误,这是正常的),我的用户名是fernando,密码是root,所以当我最终运行时,我得到以下错误消息:

Traceback (most recent call last):
  File "/home/elfstone/Documents/workspace/NuevosPython/fire.py", line 3, in <module>
    con = fdb.connect(dsn="/tmp/test.fdb", user="fernando", password="root")
  File "/home/elfstone/Downloads/fdb-1.4/fdb/fbcore.py", line 693, in connect
    "Error while connecting to database:")
fdb.fbcore.DatabaseError: ('Error while connecting to database:\n- SQLCODE: -902\n- Unable to complete network request to host "localhost".\n- Failed to establish a connection.', -902, 335544721)

如何解决? 帮助和感谢。

使用Ubuntu 12.04.4fdb 1.4.1检查,所有建议的语句类型均有效:

fdb.connect(dsn="/var/lib/firebird/2.5/data/test.fdb", user="fernando", password="root")
fdb.connect(host="localhost", database="/var/lib/firebird/2.5/data/test.fdb", user="fernando", password="root")
fdb.connect(dsn="localhost:/var/lib/firebird/2.5/data/test.fdb", user="fernando", password="root")

这未经测试,但我的怀疑是:

该错误表明您无法连接到“本地主机”,这是您正在使用的计算机的网络名称。 但是,您要求Firebird连接到“ /tmp/test.fbd”,这是文件系统位置。 基本上,firebird认为您要连接到文件“ /tmp/test.fbd”,就好像它是服务器一样。

尝试:

con = fdb.connect(host="localhost", database="/tmp/test.fdb", user="fernando", password="root")

要么

con = fdb.connect(dsn="localhost:/tmp/test.fdb", user="fernando", password="root")

当然,假设/tmp/fest.fbd实际上在您的本地主机上。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM