dailey007 / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

Could not find stored procedure #110

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Compile pyodbc 
2. cnxn = pyodbc.connect('DRIVER={FreeTDS};SERVER=%s;DATABASE=DB;UID=%s;PWD=%s' 

3. cursor.execute('EXEC STORED_PROCEDURE_NAME')

What is the expected output? What do you see instead?
Resultset of Stored Procedure
I get an error
[42000] [FreeTDS][SQL Server]Could not find stored procedure 'e'. (2812) 
(SQLExecDirectW)
although the STORED PROCEDURE is not name 'e'

What version of the product are you using? On what operating system?
Ubuntu Lucid
Django 1.2.1
pyodbc 2.1.7

Please provide any additional information below.

Original issue reported on code.google.com by min...@gmail.com on 20 Jul 2010 at 5:21

GoogleCodeExporter commented 8 years ago
I can also confirm this.

cnx_string = 'DSN=devsrv;UID=sa;PWD=...;DATABASE=...'
cnx = pyodbc.connect(cnx_string)
args = (int_arg1, int_arg2, int_arg3, string_arg4)
results = cnx.cursor().execute("EXEC stored_proc (%s, %s, %s, '%s') % 
args).fetchone()

This fails with the same error as above.

I am using the freetds-patched driver from ibiblio.org (date 20 jul 2010)
I tested with pyodbc 2.1.6 and 2.1.7 on sql server 2000 and 2008.
The os is lucid server x86_64

As a workaround, this works (tested with pyodbc 2.1.6, will test also with 
pyodbc 2.1.7)

cnx = pyodbc.connect(...)
args = (int_arg1, int_arg2, int_arg3, string_arg4.encode("utf-8"))
results = cnx.cursor().execute("{CALL stored_proc(?, ?, ?, ?)}", 
args).fetchone()

so.. using the odbc call format seems to work

Original comment by giotis.n...@gmail.com on 26 Jul 2010 at 11:10

GoogleCodeExporter commented 8 years ago
I tried the ODBC call in 2.1.7, but it reports 
('HY000', 'The driver did not supply an error!')

Original comment by min...@gmail.com on 26 Jul 2010 at 9:04

GoogleCodeExporter commented 8 years ago
I am using this driver

http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-patched.tgz
Compiled with
./configure
make
make install

This installs the driver in /usr/local/lib, and the configuration is inside 
/usr/local/etc/freetds.conf

also tested with pyodbc 2.1.7 and it works. I am using a DSN to connect to the 
db.

Also I got this error (HY000) when I passed the arguments inside the {CALL...} 
string. Maybe you should try passing the arguments as tuple in execute, like 
above

arguments = (arg1, arg2)
cur.execute("{CALL stored_proc(?, ?)}", arguments)

What i also noticed is that i need to pass string arguments as 
string.encode("utf-8")

Original comment by giotis.n...@gmail.com on 27 Jul 2010 at 6:42

GoogleCodeExporter commented 8 years ago
It sounds like the issue is a character encoding mismatch.  pyodbc 2.x will 
call the ANSI APIs if you supply an ANSI SQL statement, and it will call the 
Unicode ones if you provide a Unicode SQL statement.  Per the ODBC 
specification, the Unicode versions will be passed as SQLWCHAR, which is 
usually UCS2 encoding.  I am seeing that a lot of drivers think that decoding 
ANSI as UTF8 is acceptable, but it really isn't

Double check your connection's encoding.

Original comment by mkleehammer on 21 Nov 2010 at 6:06