I'm trying to connect to a Firebird 1.5 database that is located on a server, from my local machine with Python fdb libary.
but I'm having no luck.
the server is windows 2008 server R1 running Firebird 1.5.6 as a service. It also has a System DSN called firebird
.
How can i connect to it via python? I'm using this code:
import fdb
db = fdb.connect(host='192.168.40.28', database="C:\databases\database12.GDB", user='admin', password='admin')
but it generates this result:
Traceback (most recent call last):
File "data.py", line 4, in <module>
db = fdb.connect(host='192.168.40.28', database="C:\databases\database12.GDB", user='admin', password='admin')
File "/usr/local/lib/python2.7/dist-packages/fdb/fbcore.py", line 666, 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 "192.168.40.28".\n- Failed to establish a connection.', -902, 335544721)
what am I doing wrong here?
Assuming that the IP 192.168.40.28
is correct my next quess would be that you don't have the port 3050
open (thats the default port for Firebird). Check your server's firewall and open the port. You can use some other port instead of 3050
by seting the RemoteServicePort
parameter in the firebird.conf
file, but then you have to set the port parameter in the connect
method too.
As other answers have stated, check that port 3050 is open.
However, fdb only supports Firebird 2.0 or higher. For Firebird 1.5, you can use either pyodbc or pyfirebirdsql
Note that, among other issues (like not handling Firebird INTEGER datatypes properly), pyfirebirdsql isn't 100% compliant with PEP 249 -- Python DB API 2.0 as calls to Cursor.rowcount
always return -1.
Edit: After posting this, I took it upon myself to write the code for pyfirebirdsql's rowcount
function, so now it works as expected, instead of always returning 1. Shortly after that, the pyfirebirdsql author fixed the INTEGER issues as well.
You must to check the port open in your host as ain said. BTW, fdb is just for firebird 2.0 and higher. Check it out. https://fdb.readthedocs.org/en/latest/getting-started.html#installation
来源:https://stackoverflow.com/questions/15704760/python-fdb-trying-to-connect-to-an-external-firebird-1-5-super-server