From erik.myllymaki at aviawest.com Sun Apr 2 22:22:12 2006 From: erik.myllymaki at aviawest.com (Erik Myllymaki) Date: Mon Apr 3 14:42:03 2006 Subject: [egenix-users] errors using mxODBC with unixODBC to connect to MSSQL Message-ID: <4430A2F4.6020609@aviawest.com> I am using a script that's worked for me in the past on Windows, but now that i've moved it to a Linux machine it is not. The trouble seems to be when trying to insert escaped characters into a ntext field (\n \r ,etc.). ----------------------------------------------------------------------------- # works on Windows using this connect method # conn = mx.ODBC.WINDOWS.DriverConnect('DSN=myDSN;UID=sa;PWD=pwd') conn = mx.ODBC.unixODBC.DriverConnect('DSN=myDSN;UID=sa;PWD=pwd') curr = conn.cursor() # These strings do not work: # mystring = "Some text \n and some other text" # mystring = "Some text \t and some other text" # mystring = """Some text and some other text""" # This string works just fine: mystring = "Some text and some other text" sql_insert = "insert into DEV..msg(message_id,body) values(?,?)" curr.execute(sql_insert, (1,mystring)) curr.close() conn.commit() ----------------------------------------------------------------------------- Here's the error message: Error Type: OperationalError Error Value: ('', 8179, '[unixODBC][FreeTDS][SQL Server]Could not find prepared statement with handle 0.', 6083) Any ideas greatly appreciated. From mal at egenix.com Mon Apr 3 17:14:24 2006 From: mal at egenix.com (M.-A. Lemburg) Date: Mon Apr 3 16:14:33 2006 Subject: [egenix-users] errors using mxODBC with unixODBC to connect to MSSQL In-Reply-To: <4430A2F4.6020609@aviawest.com> References: <4430A2F4.6020609@aviawest.com> Message-ID: <44312DC0.5080700@egenix.com> Erik Myllymaki wrote: > I am using a script that's worked for me in the past on Windows, but > now that i've moved it to a Linux machine it is not. The trouble seems > to be when trying to insert escaped characters into a ntext field > (\n \r ,etc.). > > ----------------------------------------------------------------------------- > > # works on Windows using this connect method > # conn = mx.ODBC.WINDOWS.DriverConnect('DSN=myDSN;UID=sa;PWD=pwd') > > conn = mx.ODBC.unixODBC.DriverConnect('DSN=myDSN;UID=sa;PWD=pwd') > curr = conn.cursor() > > # These strings do not work: > # mystring = "Some text \n and some other text" > # mystring = "Some text \t and some other text" > # mystring = """Some text > and some other text""" > > # This string works just fine: > mystring = "Some text and some other text" > > sql_insert = "insert into DEV..msg(message_id,body) values(?,?)" > > curr.execute(sql_insert, (1,mystring)) > curr.close() > conn.commit() > ----------------------------------------------------------------------------- > > > Here's the error message: > > Error Type: OperationalError > Error Value: ('', 8179, '[unixODBC][FreeTDS][SQL Server]Could not find > prepared statement with handle 0.', 6083) > > Any ideas greatly appreciated. This sounds a lot like a bug in the FreeTDS ODBC driver. It is possible that it tries to embed the string value in the SQL command and stumbles over the non-text parts of the string, e.g. forgets to quote them properly. A look at the odbc call trace would help find out. In order to enable logging at the ODBC driver manager level, please follow these instructions: 1. edit the odbc.ini file that defines the data source you are using (usually /etc/odbc.ini or ~/.odbc.ini) 2. add two trace options to the data source in question: [MyDataSourceName] Trace = On TraceFile = /tmp/odbc.log ... 3. restart Python and run a query on the connection You should then see the /tmp/odbc.log file fill up with ODBC call trace messages. Error messages from the ODBC driver should also appear in this file. In some cases you also have to edit the file /etc/odbcinst.ini (or ~/.odbcinst.ini) and add a section: [ODBC] Trace = On TraceFile= /tmp/odbc.log -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Apr 03 2006) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From bkelly at uwsp.edu Fri Apr 7 10:17:42 2006 From: bkelly at uwsp.edu (Kelly, Brian) Date: Fri Apr 7 16:17:53 2006 Subject: [egenix-users] compile errors Message-ID: <8E9819795A47EF4588619C0CA9BAC4C405CFC256@ems5.uwsp.edu> I've installed the base package and I've already installed libiodbc but when I run python setup.py install I get hundreds of errors. I'm using python 2.4.2 and GCC 3.3.5. I have been able to get it to compile successfully on OSX using python 2.3.5 GCC 3.3. Here's a snippet of my output: running install running build running mx_autoconf i386-pc-linux-gnu-gcc -pthread -DNDEBUG -fno-strict-aliasing -fPIC -D_GNU_SOURCE=1 -I/usr/include -c _configtest.c -o _configtest.o i386-pc-linux-gnu-gcc -pthread _configtest.o -L/usr/local/lib -L/usr/lib -o _configtest success! removing: _configtest.c _configtest.o _configtest i386-pc-linux-gnu-gcc -pthread -DNDEBUG -fno-strict-aliasing -fPIC -D_GNU_SOURCE=1 -I/usr/include/python2.4 -I/usr/include -c _configtest.c -o _configtest.o success! removing: _configtest.c _configtest.o running build_ext building 'mx.ODBC.iODBC.mxODBC' extension i386-pc-linux-gnu-gcc -pthread -DNDEBUG -fno-strict-aliasing -fPIC -DiODBC -DHAVE_STRPTIME=1 -Imx/ODBC/iODBC -I/usr/local/iODBC/include -I/usr/include/python2.4 -I/usr/include -c mx/ODBC/iODBC/mxODBC.c -o build/temp.linux-i686-2.4/mx/ODBC/iODBC/mxODBC/mx/ODBC/iODBC/mxODBC.o In file included from mx/ODBC/iODBC/mxODBC.c:33: mx/ODBC/iODBC/mxODBC.h:239:19: sql.h: No such file or directory mx/ODBC/iODBC/mxODBC.h:240:22: sqlext.h: No such file or directory In file included from mx/ODBC/iODBC/mxODBC.c:33: mx/ODBC/iODBC/mxODBC.h:682: error: syntax error before "SQLHDBC" mx/ODBC/iODBC/mxODBC.h:682: warning: no semicolon at end of struct or union mx/ODBC/iODBC/mxODBC.h:699: error: syntax error before ':' token mx/ODBC/iODBC/mxODBC.h:703: warning: data definition has no type or storage class mx/ODBC/iODBC/mxODBC.h:718: error: syntax error before "SQLCHAR" mx/ODBC/iODBC/mxODBC.h:718: warning: no semicolon at end of struct or union mx/ODBC/iODBC/mxODBC.h:719: warning: data definition has no type or storage class mx/ODBC/iODBC/mxODBC.h:720: error: syntax error before "sqltype" mx/ODBC/iODBC/mxODBC.h:720: warning: data definition has no type or storage class mx/ODBC/iODBC/mxODBC.h:721: error: syntax error before "sqllen" mx/ODBC/iODBC/mxODBC.h:721: warning: data definition has no type or storage class mx/ODBC/iODBC/mxODBC.h:722: error: syntax error before "sqlscale" mx/ODBC/iODBC/mxODBC.h:722: warning: data definition has no type or storage class mx/ODBC/iODBC/mxODBC.h:723: error: syntax error before "nullable" mx/ODBC/iODBC/mxODBC.h:723: warning: data definition has no type or storage class mx/ODBC/iODBC/mxODBC.h:724: error: syntax error before "ctype" mx/ODBC/iODBC/mxODBC.h:724: warning: data definition has no type or storage class mx/ODBC/iODBC/mxODBC.h:727: error: syntax error before "data" Any insight into what these error messages mean would be appreciated. Thanks, Brian Kelly From mal at egenix.com Fri Apr 7 19:14:41 2006 From: mal at egenix.com (M.-A. Lemburg) Date: Fri Apr 7 18:14:49 2006 Subject: [egenix-users] compile errors In-Reply-To: <8E9819795A47EF4588619C0CA9BAC4C405CFC256@ems5.uwsp.edu> References: <8E9819795A47EF4588619C0CA9BAC4C405CFC256@ems5.uwsp.edu> Message-ID: <44368FF1.7020006@egenix.com> Kelly, Brian wrote: > I've installed the base package and I've already installed libiodbc but > when I run python setup.py install I get hundreds of errors. I'm using > python 2.4.2 and GCC 3.3.5. I have been able to get it to compile > successfully on OSX using python 2.3.5 GCC 3.3. > > Here's a snippet of my output: > > running install > running build > running mx_autoconf > i386-pc-linux-gnu-gcc -pthread -DNDEBUG -fno-strict-aliasing -fPIC > -D_GNU_SOURCE=1 -I/usr/include -c _configtest.c -o _configtest.o > i386-pc-linux-gnu-gcc -pthread _configtest.o -L/usr/local/lib -L/usr/lib > -o _configtest > success! > removing: _configtest.c _configtest.o _configtest > i386-pc-linux-gnu-gcc -pthread -DNDEBUG -fno-strict-aliasing -fPIC > -D_GNU_SOURCE=1 -I/usr/include/python2.4 -I/usr/include -c _configtest.c > -o _configtest.o > success! > removing: _configtest.c _configtest.o > running build_ext > building 'mx.ODBC.iODBC.mxODBC' extension > i386-pc-linux-gnu-gcc -pthread -DNDEBUG -fno-strict-aliasing -fPIC > -DiODBC -DHAVE_STRPTIME=1 -Imx/ODBC/iODBC -I/usr/local/iODBC/include > -I/usr/include/python2.4 -I/usr/include -c mx/ODBC/iODBC/mxODBC.c -o > build/temp.linux-i686-2.4/mx/ODBC/iODBC/mxODBC/mx/ODBC/iODBC/mxODBC.o > > In file included from mx/ODBC/iODBC/mxODBC.c:33: > mx/ODBC/iODBC/mxODBC.h:239:19: sql.h: No such file or directory > mx/ODBC/iODBC/mxODBC.h:240:22: sqlext.h: No such file or directory The compiler can't find or read the iODBC header files. Please make sure these are in /usr/include (where they should be per default on Mac OS X) and readable. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Apr 07 2006) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: From john.corry at ntlworld.com Sat Apr 15 15:13:29 2006 From: john.corry at ntlworld.com (John CORRY) Date: Sun Apr 16 10:43:18 2006 Subject: [egenix-users] Difficulty connecting Message-ID: <000001c6608e$678a0980$4a3ea8c0@JOHNC> Hi, I am very new to python and programming. I am using windows xp, python 2.4 and I am trying to log onto a visual foxpro database file. I have downloaded the visual foxpro driver. I use the following code: import mx.ODBC import mx.ODBC.Windows db = mx.ODBC.Windows.DriverConnect('dsn=c:/test/m2m/data/cost_grid.dbf') c = db.cursor() and I get the following error: Traceback (most recent call last): File "C:\Python24\Lib\site-packages\databasemanager.py", line 4, in ? db = mx.ODBC.Windows.DriverConnect('dsn=c:/test/m2m/data/cost_grid.dbf') OperationalError: ('IM002', 0, '[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified', 6044) What am I doing wrong and what do I need to do? Any help would be greatly appreciated. Thanks, John. -------------- next part -------------- An HTML attachment was scrubbed... URL: /mailman-archives/egenix-users/attachments/20060415/910afe3b/attachment.htm From john.corry at ntlworld.com Sat Apr 15 17:36:34 2006 From: john.corry at ntlworld.com (John CORRY) Date: Sun Apr 16 10:43:34 2006 Subject: [egenix-users] FW: Difficulty connecting Message-ID: <000001c660a2$62619a90$4a3ea8c0@JOHNC> Hi, I am very new to python and programming. I am using windows xp, python 2.4 and I am trying to log onto a visual foxpro database file. I have downloaded the visual foxpro driver. I use the following code: import mx.ODBC import mx.ODBC.Windows db = mx.ODBC.Windows.DriverConnect('dsn=c:/test/m2m/data/cost_grid.dbf') c = db.cursor() and I get the following error: Traceback (most recent call last): File "C:\Python24\Lib\site-packages\databasemanager.py", line 4, in ? db = mx.ODBC.Windows.DriverConnect('dsn=c:/test/m2m/data/cost_grid.dbf') OperationalError: ('IM002', 0, '[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified', 6044) What am I doing wrong and what do I need to do? Any help would be greatly appreciated. Thanks, John. -------------- next part -------------- An HTML attachment was scrubbed... URL: /mailman-archives/egenix-users/attachments/20060415/30f10819/attachment.htm From charlie at egenix.com Sun Apr 16 11:55:27 2006 From: charlie at egenix.com (Charlie Clark) Date: Sun Apr 16 10:56:14 2006 Subject: [egenix-users] Difficulty connecting In-Reply-To: <000001c6608e$678a0980$4a3ea8c0@JOHNC> References: <000001c6608e$678a0980$4a3ea8c0@JOHNC> Message-ID: <4442067F.7080904@egenix.com> John CORRY wrote: > Hi, > > I am very new to python and programming. I am using windows xp, python > 2.4 and I am trying to log onto a visual foxpro database file. I have > downloaded the visual foxpro driver. I use the following code: > > import mx.ODBC > import mx.ODBC.Windows > db = mx.ODBC.Windows.DriverConnect('dsn=c:/test/m2m/data/cost_grid.dbf') > c = db.cursor() > > and I get the following error: > > Traceback (most recent call last): > File "C:\Python24\Lib\site-packages\databasemanager.py", line 4, in ? > db = > mx.ODBC.Windows.DriverConnect('dsn=c:/test/m2m/data/cost_grid.dbf') > OperationalError: ('IM002', 0, '[Microsoft][ODBC Driver Manager] Data > source name not found and no default driver specified', 6044) > > What am I doing wrong and what do I need to do? Any help would be > greatly appreciated. John, The error message is quite clear: Python cannot connect to the data source you have given. It is always best to set up ODBC data sources using an ODBC manager. In Windows this is done through Control Panel -> Administration -> Data Sources. Set up your data source and test it here before trying to connect using Python. Charlie From john.corry at ntlworld.com Sun Apr 16 11:39:14 2006 From: john.corry at ntlworld.com (John Corry) Date: Sun Apr 16 11:29:39 2006 Subject: [egenix-users] Difficulty connecting In-Reply-To: <4442067F.7080904@egenix.com> Message-ID: Charlie, Thanks for the help. I am now up and running. Regards, John. -----Original Message----- From: Charlie Clark [mailto:charlie@egenix.com] Sent: 16 April 2006 09:55 To: john.corry@ntlworld.com Cc: egenix-users@egenix.com Subject: Re: [egenix-users] Difficulty connecting John CORRY wrote: > Hi, > > I am very new to python and programming. I am using windows xp, python > 2.4 and I am trying to log onto a visual foxpro database file. I have > downloaded the visual foxpro driver. I use the following code: > > import mx.ODBC > import mx.ODBC.Windows > db = mx.ODBC.Windows.DriverConnect('dsn=c:/test/m2m/data/cost_grid.dbf') > c = db.cursor() > > and I get the following error: > > Traceback (most recent call last): > File "C:\Python24\Lib\site-packages\databasemanager.py", line 4, in ? > db = > mx.ODBC.Windows.DriverConnect('dsn=c:/test/m2m/data/cost_grid.dbf') > OperationalError: ('IM002', 0, '[Microsoft][ODBC Driver Manager] Data > source name not found and no default driver specified', 6044) > > What am I doing wrong and what do I need to do? Any help would be > greatly appreciated. John, The error message is quite clear: Python cannot connect to the data source you have given. It is always best to set up ODBC data sources using an ODBC manager. In Windows this is done through Control Panel -> Administration -> Data Sources. Set up your data source and test it here before trying to connect using Python. Charlie