Hi, I have an .sdf file (SQL CE 3.5) that someone has given me. I need to extract some data from the file (and will need to extract similar data from similar files in the future). I'm trying to write a python script to do it.
The DB file has a table (Profiles) with three items (DataID (int), Data (varbinary[8000], CreationDate(datetime)). I am having a problem accessing the varbinary data in Data. Here's a code snippet that works for the CreationDate. ==== Begin Code (test.py) ==== import adodbapi file = "D:\\Not_Synced\\Code\\GetProfile\\20120516_111500\\ProfileDB.1.1.sdf" connstr = 'Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5; Data Source=%s;' % file conn = adodbapi.connect(connstr) cur = conn.cursor() sql = "select CreationDate from Profiles where DataID = 2" cur.execute(sql) result = cur.fetchall() for item in result: print item cur.close() conn.close() ==== End Code ==== ==== Begin Output ==== D:\Not_Synced\Code\GetProfile\20120516_111500>python test.py adodbapi v2.4.2.2 attempting: "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5; Data S ource=D:\Not_Synced\Code\GetProfile\20120516_111500\ProfilesDB.1.1.sdf;" adodbapi New connection at 2C034F0 adodbapi New cursor at 2C03B50 on conn 2C034F0 Executing command="select CreationDate from Profiles where DataID = 2" ('2012-01-18 10:54:19.843000',) adodbapi Closed connection at 2C034F0 ==== End Output ==== That code snippet accesses the date just fine. However, when I try to access the Data by changing the select command: sql = "select CreationDate from Profiles where DataID = 2" I get the following error. ==== Begin Output2 ==== D:\Not_Synced\Code\GetProfile\20120516_111500>python test2.py adodbapi v2.4.2.2 attempting: "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5; Data S ource=D:\Not_Synced\Code\GetProfile\20120516_111500\ProfilesDB.1.1.sdf" adodbapi New connection at 2C834F0 adodbapi New cursor at 2C83B50 on conn 2C834F0 Executing command="select Data from Profiles where DataID = 2" Traceback (most recent call last): File "test.py", line 9, in <module> cur.execute(sql) File "e:\Python27\lib\site-packages\adodbapi\adodbapi.py", line 1008, in execu te self._execute_command() File "e:\Python27\lib\site-packages\adodbapi\adodbapi.py", line 893, in _execu te_command self._raiseCursorError(klass, _message) File "e:\Python27\lib\site-packages\adodbapi\adodbapi.py", line 758, in _raise CursorError eh(self.connection,self,errorclass,errorvalue) File "e:\Python27\lib\site-packages\adodbapi\adodbapi.py", line 107, in standa rdErrorHandler raise errorclass(errorvalue) adodbapi.adodbapi.DatabaseError: (-2147352567, 'Exception occurred.', (0, u'Micr osoft SQL Server Compact OLE DB Provider', u'Multiple-step OLE DB operation gene rated errors. Check each OLE DB status value, if available. No work was done.', None, 0, -2147217887), None) Command: select Data from Profiles where DataID = 2 Parameters: [] adodbapi Closed connection at 2C834F0 ==== End Output2 ==== Any help you could provide would be greatly appreciated. Thanks. --Dave PS I'm using Win7 x64 with a Python 2.7 (32 bit) installation. -- David L. Page davidp...@ieee.org
_______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32