Subject | cannot connect to an embedded firebird database using Python (.NET client works) |
---|---|
Author | btapkan |
Post date | 2012-10-11T18:52:16Z |
Hello,
Hope everyone is doing well. Having this problem of not being able to connect to an existing embedded Firebird database using Python.
I work regularly on a Windows 7 x64-bit, Python 2.7 (switched to 2.6 for kinterbasdb w/o success, then switch back). I also have a licensed copy of Firebird Maestro. Tried three different library packages:
- firebirdsql (relatively new, but does not seem to have support for embedded) (http://pypi.python.org/pypi/firebirdsql)
- kinterbasdb (last update was in 2010, seemed to install) (
- fdb (could not install either on Windows or MacOS).(http://pypi.python.org/pypi/fdb)
have the bellow code (basically trying to invoke the sample code on the documentation:
# import firebirdsql
import kinterbasdb
# the server is named test.fsdb
# con = firebirdsql.connect(dsn='TEST.FDB', user='SYSDBA', password='masterkey')
con = kinterbasdb.connect(host='', database=r'C:\src\python\pyfirebirdsql\TEST.FDB',user='sysdba', password='masterkey')
cur = con.cursor()
# execute the select statement
cur.execute("select * from languages order by year_released")
# retrieve all rows in a sequence and print the sequence
print cur.fetchall()
TEST.FDB file is in the same directory as I am running the script. With firebirdsql package, I receive below:
c:\src\python\pyfirebirdsql>python fsdb_test.py
Traceback (most recent call last):
File "fsdb_test.py", line 5, in <module>
con = firebirdsql.connect(dsn='TEST.FDB', user='SYSDBA', password='masterkey')
File "c:\src\python\pyfirebirdsql\firebirdsql\__init__.py", line 64, in connect
database=database, charset=charset, port=port)
File "c:\src\python\pyfirebirdsql\firebirdsql\fbcore.py", line 759, in __init__
self.sock.connect((self.hostname, self.port))
File "C:\Python27\lib\socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it
Looks like support for embedded is missing for firebirdsql.
With kinterbasdb, I get this:
c:\src\python\pyfirebirdsql>python fsdb_test.py
Traceback (most recent call last):
File "fsdb_test.py", line 2, in <module>
import kinterbasdb
File "C:\Python27\lib\site-packages\kinterbasdb\__init__.py", line 119, in <module>
import _kinterbasdb as _k
ImportError: DLL load failed: %1 is not a valid Win32 application.
This is 32 bit vs 64-bit issue looks like. I made sure I used both 64-bit editions of Python 2.7 and kinterbasdb-3.3.0. Still getting this message. Created an embedded folder as described here in the Python27\Lib\site-packages\kinterbasdb\embedded and copied the three DLLS (unblocked on Windows).
Could not even install fdb using below command:
c:\src\python\fdb-0.9.1>python setup.py build
Traceback (most recent call last):
File "setup.py", line 7, in <module>
from fdb import __version__
File "c:\src\python\fdb-0.9.1\fdb\__init__.py", line 23, in <module>
from fdb.fbcore import *
File "c:\src\python\fdb-0.9.1\fdb\fbcore.py", line 26, in <module>
from . import ibase
File "c:\src\python\fdb-0.9.1\fdb\ibase.py", line 39, in <module>
fb_library = WinDLL(fb_library_name)
File "C:\Python27\lib\ctypes\__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
TypeError: expected string or Unicode object, NoneType found
Just to see if embedded works, I switched to .NET (sigh) and able to connect to the same database using the below:
class Program
{
static void Main(string[] args)
{
string ConnectionString = "Database=E:\\TEST.FDB;User=SYSDBA;Password=masterkey;Dialect=3;ServerType=1";
FbConnection addDetailsConnection = new FbConnection(ConnectionString);
addDetailsConnection.Open();
Console.WriteLine("connection open");
Console.ReadLine();
addDetailsConnection.Close();
Console.WriteLine("connection closed");
Console.ReadLine();
}
}
For .NET, I followed the detailed and easy-to-follow instructions found here. http://nazmialtun.blogspot.com/2012/01/using-embedded-firebird-database-in-net.html
Any help, expertise with the above would be appreciated. Thanks!
Baskin Tapkan