pyodbc error calling iSeries stored procedure - pyodbc

Getting this error message when calling a stored proc from python script to iSeries pgm, pyodbc.Error: ('HY000', '[HY000] [IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0443
- Trigger program or external routine detected an error. (-443) (SQLExecDirectW)')
My dsn is set up as
with pyodbc.connect(dsn=dsn_name, autocommit=True) as connection:
cursor = connection.cursor()
try:
log.info("Calling proc IPP201CSP (CL IPP201C) with no parameters")
cursor.execute("{CALL IPP201CSP}")
'''
Already saw this which seems to say add autocommit=True which is what I have https://stackoverflow.com/questions/36927687/error-when-calling-a-procedure-from-pyodbc

Related

R teradata DBI:dbConnect() error: TimedOut: No response received when attempting to connect to the Teradata server

I am going to ask and answer this question because I spent more time than I'd like to admit searching for a response and couldn't find one. I installed Teradata ODBC Driver 16.20. In the ODBC Data Source Administrator, I added a Data Source. I named it teradata, put in the name of the Teradata Server to connect to and my username and password for authentication. When I tried running the following code in RStudio:
con <- DBI::dbConnect(odbc::odbc(),
"teradata")
I would get an error:
Error: nanodbc/nanodbc.cpp:1021: HY000: [Teradata][WSock32 DLL] (434) WSA E TimedOut: No response received when attempting to connect to the Teradata server
To solve this, I needed to pass a timeout argument:
con <- DBI::dbConnect(odbc::odbc(),
"teradata",
timeout = 20)

more info for R DBI::dbSendQuery?

Here is a line of code that used to work:
res <- DBI::dbSendQuery(con, "SELECT 1")
Now it says:
Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set for ", :
Unable to retrieve JDBC result set for SELECT 1 (Error executing query)
I'm connecting to a Presto instance. Likely there's a connection problem or some other non-SQL problem.
How do I get more logging or debug information from this interface? I'm using DBI 0.7, R 3.4.3 on OS X (darwin15.6.0).
I read some of the docs, and I don't see an interface to turn on logging, or debug info. Maybe a connection parameter?

Error connecting to DB2 via ODBC

I'm having trouble connecting to a DB2 database via ODBC. I'm on a Windows system, and have configured a Data Source Name within the ODBC Administrator. When I test the connection there I get Connection tested successfully.. I can also successfully test the connection within IBM's DB2 Configuration Assistant, using both CLI and ODBC.
I'm not able to connect within R. I've tried both the RODBC & odbc packages, the result is the same. My intent is to execute a simple query to verify the connection. When I run the following R script I get an error. Here's my pseudocode.
library('RODBC')
myQuery <- 'SELECT COLUMN1, COLUMN2 FROM DATABASE.TABLE FETCH FIRST 10 ROWS ONLY;'
cnxn <- odbcConnect('myDSN')
data <- sqlQuery(channel=cnxn, query=myQuery)
odbcCloseAll()
Here's the error that I get.
Error in sqlQuery(channel = cnxn, query = myQuery) :
first argument is not an open RODBC channel
In addition: Warning messages:
1: In RODBC::odbcDriverConnect("DSN=myDSN") :
[RODBC] ERROR: state 58031, code -1031, message [IBM][CLI Driver] SQL1031N The database directory cannot be found on the indicated file system. SQLSTATE=58031
2: In RODBC::odbcDriverConnect("DSN=myDSN") : ODBC connection failed
I've learned through experimentation that my script never gets to the point of sending the query. This error is generated at the odbcConnect command.
I don't have access to the server itself, only the database. Is there anything that I can do or try to resolve this on my own, without having to go through support?
EDIT:
I've now cataloged my database, and test connection is successful in 3 places, ODBC Data Source Administrator, Db2 Command Line & Db2 Configuration Assistant. I know that there's no issue with permissions, as I can execute queries via IBM Query Management Facility. I believe this is an issue with either my driver or my system's PATH statements, but I'm not sure how to trace that down.
Taking a non-RODBC approach, the below method works for connecting R and DB2. Assuming you know all the information below, you'll need to download an IBM DB2 jar file and locate it, in this case, in a folder on my machine called "IBM".
Note: there are two types of available jar files, db2jcc.jar and db2jcc4.jar. The below example is using db2jcc.jar.
library(rJava)
library(RJDBC)
library(DBI)
#Enter the values for you database connection
dsn_driver = "com.ibm.db2.jcc.DB2Driver"
dsn_database = "" # e.g. "BLUDB"
dsn_hostname = "" # e.g.: "awh-yp-small03.services.dal.bluemix.net"
dsn_port = "" # e.g. "50000"
dsn_protocol = "TCPIP" # i.e. "TCPIP"
dsn_uid = "" # e.g. "dash104434"
dsn_pwd = "" # e.g. "7dBZ39xN6$o0JiX!m"
jcc = JDBC("com.ibm.db2.jcc.DB2Driver", "C:/Program Files/IBM/SQLLIB/java/db2jcc.jar");
jdbc_path = paste("jdbc:db2://", dsn_hostname, ":", dsn_port, "/", dsn_database, sep="");
conn = dbConnect(jcc, jdbc_path, user=dsn_uid, password=dsn_pwd)
query = "SELECT *
FROM Table
FETCH FIRST 10 ROWS ONLY";
rs = dbSendQuery(conn, query);
df = fetch(rs, -1);
df
According to the DB2 Manual here
SQL1031N The database directory cannot be found on the indicated file system.
Explanation
The system database directory or local database directory could not be found. A database has not been created or it was not cataloged correctly.
The command cannot be processed.
User response
Verify that the database is created with the correct path specification. The Catalog Database command has a path parameter which specifies the directory where the database resides.
sqlcode: -1031
sqlstate: 58031

pyodbc cannot connect whereas similar connection works with RODBC

I try to connect to my DB with the following request:
import pyodbc
connectionString = "driver={Adaptive Server Enterprise};database=#DB#;Server=#Server#;port=#port#;UID=#UID#;PWD=#PWD#;"
pyodbc.connect(connectionString)
However I get the following error, as if my connection string is not correct:
Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source
name not found and no default driver specified (0)
(SQLDriverConnect)')
Which is strange, since I managed to connect to my DB in R with ROBC module.
library(RODBC)
ch = odbcDriverConnect(connection = connectionString)
Any idea what is wrong with my connection string in pyodbc ?
I resolved my problem, the request is working with 32-bits python interpreter.
It appears not to be 64bits compatible.
Similar topic here: cannot connect to 64bit MsAccess database with 64bit Python 3.6.ODBC Driver Error

SAS connection to Teradata Database using Teradata ODBC

I'm trying to connect to Teradata in SAS. I set up an teradata ODBC on the machine. The assumption currently for me is that using ODBC is the only way for me to access the database. And here is the syntax of my connection command:
Libname Teradata ODBC dsn = 'dsnname' uid = 'uid' pwd = 'pwd';
results:
Error: The ODBC engine cannot be found.
Error: Error in the LIBNAME statement.
It keeps saying that the ODBC engine cannot be found. I'm really confused now. Is there anything wrong with the command? Or I have to do something else outside SAS?
I check the licence
Proc Setinit;
result:
SAS/ACCESS Interface to Teradata ** the date shows not expired.
Could anyone give me some idea. Thank you very much!
Can't say I've ever used ODBC to access Teradata, can see it being highly inefficient.
Normally, you'd do pass-thru SQL to Teradata...
proc sql ;
connect to teradata (user='username' pass='password' tdpid=prodserver) ;
create table mydata as
select * from connection to teradata
(select a.*
from ds.enterprise_table as a) ;
disconnect from teradata ;
quit ;
For a direct libname, the syntax would be
libname tdata teradata user='username' pass='password' tdpid=prodserver schema=ds ;
data mydata ;
set tdata.enterprise_table ;
run ;

Resources