I’m developing plugin for Acrobat in C++. I’ve downloaded Abode SDK and use BasicPlugin template as my starting point. In plugin I want to read my database via ODBC (my intention later to update database with some details about opened PDF file). But I got stuck here. I cannot establish connection to my database. The error I’ve received reads that server is not available or access denied.
Though when I use the same code for accessing to database in console app – everything is working correctly.
My code for access to database from plugin code looks like how below:
SQLHENV henv;
SQLHDBC hdbc;
SQLHSTMT hstmt;
SQLRETURN ret;
// Allocate environment handle
ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
// Set ODBC version
ret = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);
// Allocate connection handle
ret = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
// Connect to the database (replace with your DSN)
ret = SQLConnect(hdbc, (SQLCHAR*)"myDSN", SQL_NTS, NULL, 0, NULL, 0);
// Allocate statement handle
ret = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
// Execute a query (replace with your SQL query)
ret = SQLExecDirect(hstmt, (SQLCHAR*)"select column1 from table", SQL_NTS);
// Fetch and print results
while (SQLFetch(hstmt) == SQL_SUCCESS) {
SQLCHAR name[256];
SQLINTEGER id;
ret = SQLGetData(hstmt, 1, SQL_C_CHAR, name, sizeof(name), NULL);
ret = SQLGetData(hstmt, 2, SQL_C_LONG, &id, 0, NULL);
printf("Name: %s, ID: %dn", name, id);
}
// Clean up
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
SQLDisconnect(hdbc);
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
SQLFreeHandle(SQL_HANDLE_ENV, henv);
Can anybody assist with this problem as provide some details how I can fix this issue?
And also more common questions:
Should I configure some permission/restriction logic in my plugin to make access to ODBC data available, or plugin doesn’t support such logic and I cannot access my Database from plugin?
The code above is working good in Console app, and doesn’t work inside plugin
Mikalai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.