Using DacSession to access data via ODBCDBE
Posted: Wed Feb 20, 2019 9:16 am
I'm trying to access a dataset using dacsession and odbcdbe. The dataset uses .SAM flat files (which may be the issue; I'm not sure).
I can connect fine using the following code:
However, when I try to access the data I run into issues.
Using DacSession's :ExecuteQuery() or :ExecuteStatement() like the following:
Gives me the error message: Operation not supported by this dbe (operation: dacExecuteQuery)
When I try accessing the data using the commands USE or SQL like the following:
I get the following error: File can not be opened (operation: DBUseArea)
I tried the same thing in Python, and it works:
The Python code retrieves the data with no issue, so it doesn't look like an issue in the connection string. Does anyone know why this isn't working in Xbase?
I can connect fine using the following code:
Code: Select all
/*** Set connection string ***/
cConnect := "DBE=ODBCDBE"
cConnect += ";DRIVER=AdagioDataSourceDriver"
cConnect += ";COLUMNS=COMMON"
cConnect += ";DBDIRECTORY=C:\Softrak\ODBCV2\SAMDATA"
cConnect += ";DBQ=C:\Softrak\ODBCV2\SAMDATA\SAM"
cConnect += ";DBFILTER=ar9*"
cConnect += ";DBSELELECTOR=SAM"
cConnect += ";NAMES=SHORT"
cConnect += ";USERID=SYS"
cConnect += ";PASSWORD=SYS"
cConnect += ";RAWPASSWORD=1"
cConnect += ";TABLESALL=FALSE"
/*** Create dacsession ***/
oSession := DacSession():New(cConnect)
/*** Test for connection success ***/
IF ! oSession:IsConnected()
DC_Winalert("Connection failed")
wtf "ERROR code: " + AllTrim(Str(oSession:GetLastError())), ;
"Description: " + AllTrim(oSession:GetLastMessage()) pause
RETURN NIL
ENDIF
/*** Success message ***/
DC_Winalert("Connection to server established")
Using DacSession's :ExecuteQuery() or :ExecuteStatement() like the following:
Code: Select all
oSession:ExecuteQuery('SELECT Name FROM ar92acst')
When I try accessing the data using the commands USE or SQL like the following:
Code: Select all
USE 'ar92acst'
SQL "SELECT Name FROM ar92acst"
I tried the same thing in Python, and it works:
Code: Select all
import pyodbc
# Create statement to connect to driver
driverConnect = 'DRIVER={AdagioDataSourceDriver}' + \
';COLUMNS=COMMON' + \
';DBDIRECTORY=C:\\Softrak\\ODBCV2\\SAMDATA' + \
';DBQ=C:\\Softrak\\ODBCV2\\SAMDATA\\SAM' + \
';DBFILTER=ar9*' + \
';DBSELELECTOR=SAM' + \
';NAMES=SHORT' + \
';USERID=SYS' + \
';PASSWORD=SYS' + \
';RAWPASSWORD=1' + \
';TABLESALL=FALSE'
# Connect to odbc using driver
#connection = pyodbc.connect(driverConnect)
# Get cursor
cursor = connection.cursor()
# Execute select statement
cursor.execute("SELECT Name FROM ar92acst")
row = cursor.fetchone()
while row:
print(row[0])
row = cursor.fetchone()