SQL Error -4903 when trying to connect to DB2 database - sql

I am getting an SQL error code of -4903 when trying to connect to a DB2 database using SQC code (this is an ANSI C application so I need to use SQC for SQL queries). When I look at IBM's website to see what a -4903 means, all it says is "The length of parameter n of function name is not valid". However I have no idea which parameter or function it is referring to. I have tried looking at the SQLCA objects members, but I am unable to see them in Visual Studio 2015.
This is an ANSI C application debugging in Visual Studio 2015. I am able to connect to the same database using a DB2 command prompt (i.e, by running "db2 connect to dbname user username using password". However when I try to do this in code I get the -4903 error. I have also tried this on two different OS's, Windows 7 and Windows 10. I have colleagues who have had no trouble doing this on a Windows 7 machine.
while ((retry++ < 3)
|| (sqlca.sqlcode == -30080)
|| (sqlca.sqlcode == -900 ) )
{
EXEC SQL CONNECT TO :DBName USER :userid USING :pword;
if ((SQLCODE == 0 ) || (SQLCODE == (-1026)))
{
return(1);
}
else
{
dbLogAudit(KLCB, PLCB, KLLOGSEV(T),
"Retry DBInit/sqlca.sqlcode : %i", sqlca.sqlcode);
}
}
I expect the SQLCODE to be 0, which indicates a successful connection, and for the function to return 1 to it's caller. But instead the sqlca.sqlcode variable is -4903 (which I described above).
EDIT: I found the parameters being passed into the error message. The full error text is "The length of parameter runtime_pid of function sqlastrt_trusted is not valid".

I solved my own issue. Thanks to Mao for the help on debugging this one.
My development environment for DB2 was running version 8.1.0, which uses 162 bytes for the struct called "sqla_program_id". However, the runtime environment, which uses 292 bytes for that same struct, was version 10.5. Once I upgraded my development DB2 instance to v10.5 it worked like a charm.

Related

Invalid operation result set is closed errorcode 4470 sqlstate null - DB2 data extract

I am running a very simple query and trying to extract the results to a text file. The entire query is essentially what is below, I am selecting everything from one single table with one piece of where criteria which is limiting the data to one month's worth. After it has extracted around 1.2 gig this error shows up. Is there any way that I can work around this other than extracting smaller date ranges? I am trying to pull a couple of years worth of data so if I can only get it a few days at a time it will take a lot of manual work.
I am currently using the free trial of a DB2 query tool - Razor SQL if that makes a difference, I can probably purchase different software if it would help. I am trying to get IBM's tool but for some reason it freezes during the download so I am still working on that. I have searched about this error but everything I see seems much more complex than what I am doing and I can't tell if it applies or not. Thanks in advance.
select *
from MyTable
where date_col between date '2014-01-01' and date '2014-01-31'
I stumbled at this error too, found out it is related to db2jcc.jar (type 4) driver.
Excerpt: If there are no items in the result set left (or to begin with), the Result set is closed automatically and therefore the Exception. Suggestion is to handle it in the application, perhaps in my case, I started checking if(rs.next()) but otherwise, there is a work around. Check out the source link below for how you can set some properties to Data source and avoid exception.
Source :
"Invalid operation: result set is closed" error with Data Server Driver for JDBC
In my case, i missed some properties in WAS, after add allowNextOnExhaustedResultSet the issue is fixed.
1.Log in to the WebSphere Application Server administration console.
2.Select Resources > JDBC > Data sources > Application Center DataSource name > Custom properties and click New.
3.In the Name field, enter allowNextOnExhaustedResultSet.
4.In the Value field, type 1.
5.Change the type to java.lang.Integer.
6.Click OK.
Sometimes you need also check whether resultSetHoldability properties exists. Details refer to here.
I encountered this failure also when ugrading from JDBC Type 2 driver (db2java.zip) JDBC type 4 driver (db2jcc4.jar)
Statement statement = results.getStatement();
if (statement != null)
{
connection = statement.getConnection(); // ** failed here
statement.close();
}
Solution was to check if the statement is closed or not as follows.
Changed to:
Statement statement = results.getStatement();
if (statement != null && !statement.isClosed()) {
{
connection = statement.getConnection();
statement.close();
}
Creating property bellow with type Integer it's worked for me:
allowNextOnExhaustedResultSet:
I had the same issue on WAS 7 so i had to add and change few this on Admin Console.
This TeamWorksRuntimeException exception should be fixed by applying APAR JR50863 which is available on top of BPM V8.5.5 or included on BPM V8.5 refresh pack 6.
For the case that the APAR does not solve the problem, try following workaround:
Log in to the WebSphere Application Server admin console
Select Resources > JDBC > Data sources > DataSource name (TeamWorksDB) > Custom properties and click New
In the Name field, enter downgradeHoldCursorsUnderXa
In the Value field, type true
Change the type to java.lang.Boolean
Click OK to save your changes
Select custom property resultSetHoldability
In the Value field, type 1
Click OK to save your changes
Source of the Answer : https://developer.ibm.com/answers/questions/194821/invalid-operation-result-set-is-closed-errorcode-4/
Restarting the app may fix the problem if connection pool lost session to Db2. If using Tomcat then connection pool property of 'testonBorrow' may reestablish the connection to Db2.

SQL STATE 37000 [Microsoft][ODBC Microsoft Access Driver] Syntax Error or Access Violation

Good day!
I get this error:
SQL STATE 37000 [Microsoft][ODBC Microsoft Access Driver] Syntax Error
or Access Violation, when trying to run an embedded SQL statement on
Powerscript.
I am using MsSQL Server 2008 and PowerBuilder 10.5, the OS is Windows 7. I was able to determine one of the queries that is causing the problem:
SELECT top 1 CONVERT(DATETIME,:ls_datetime)
into :ldtme_datetime
from employee_information
USING SQLCA;
if SQLCA.SQLCODE = -1 then
Messagebox('SQL ERROR',SQLCA.SQLERRTEXT)
return -1
end if
I was able to come up with a solution to this by just using the datetime() function of PowerBuilder. But there are other parts of the program that is causing this and I am having a hard time in identifying which part of the program causes this. I find this very weird because I am running the same scripts here in my dev-pc with no problems at all, but when trying to run the program on my client's workstation I am getting this error. I haven't found any differences in the workstation and my dev-pc. I also tried following the instructions here, but the problem still occurs.
UPDATE: I was able to identify the other script that is causing the problem:
/////////////////////////////////////////////////////////////////////////////
// f_datediff
// Computes the time difference (in number of minutes) between adtme_datefrom and adtme_dateto
////////////////////////////
decimal ld_time_diff
SELECT top 1 DATEDIFF(MINUTE,:adtme_datefrom,:adtme_dateto)
into :ld_time_diff
FROM EMPLOYEE_INFORMATION
USING SQLCA;
if SQLCA.SQLCODE = -1 then
Messagebox('SQL ERROR',SQLCA.SQLERRTEXT)
return -1
end if
return ld_time_diff
Seems like passing datetime variables causes the error above. Other scripts are working fine.
Create a transaction user object inherited trom transaction.
Put logic in the sqlpreview of your object to capture and log the sql statement being sent to the db.
Instantiate it, connect to the db, and use it in your embedded sql.
Assuming the user gets the error you can then check what was being sent to the db and go from there.
The error in your first statement should be the second parameter to CONVERT function.
It's type is not a string, it's type is an valid expression
https://learn.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql
So I would expect that your
CONVERT(DATETIME,:ls_datetime)
would evaluate to
CONVERT(DATETIME, 'ls_datetime')
but it should be
CONVERT(DATETIME, DateTimeColumn)
The error in your second statement could be that you're providing an wrong datetime format.
So please check if your error still occurs when you use this function
https://learn.microsoft.com/en-us/sql/t-sql/statements/set-dateformat-transact-sql
with the correct datetime format you're using

DB2 error code -991

I'm getting a return code of -991 upon running a db2 batch cobol program.
The program is attempting to fetch 65 rows within a cursor structure.
I cannot find anything on this particular error, does anyone know what it means ?
You probably want to look at the db2 documentation.
Error code -991 is here.
It says:
-991
CALL ATTACH WAS UNABLE TO ESTABLISH AN IMPLICIT CONNECT OR OPEN TO DB2. RC1= rc1 RC2= rc2
Explanation
Call attach attempted to perform an implicit connect and open as the result of an SQL statement. The connect or open failed with the returned values.
rc1
The value returned in FRBRC1 for the failed CONNECT or OPEN request.
rc2
The value returned in FRBRC2 for the failed CONNECT or OPEN request.
System action
The statement cannot be processed.
Programmer response
Verify that the application intended to use the call attachment facility (CAF) as the mechanism to connect to DB2®. For functions or stored procedures running in the WLM-established stored procedure address space the application must be link-edited with or dynamically allocate the RRS attachment language interface module (DSNRLI), not CAF.
SQLSTATE
57015
Hopefully that means something to you :)
In case you're still stuck, my google-fu is strong.
SQLCODE -991, Error: CALL ATTACH WAS UNABLE TO ESTABLISH AN IMPLICIT CONNECT OR OPEN TO DB2. RC1= RC2=
From http://theamericanprogrammer.com/programming/sqlcodes.shtml

Delphi - Either BOF or EOF is True, or the current record has been deleted

This error showed when I tried to select on an empty table in MS SQL Server 2005: "either BOF or EOF is True, or the current record has been deleted". I have used TADOConnection and TADODataSet in Delphi 5 to connect and retrieve data from the database.
Conn := TADOConnection.Create(nil);
DataSet := TADODataSet.Create(nil);
Conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=sa;' +
'Persist Security Info=True;' +
'User ID=user;Initial Catalog=mydb;' +
'Data Source=MYPC\SQLEXPRESS;' +
'Use Procedure for Prepare=1;' +
'Auto Translate=True;Packet Size=4096;' +
'Workstation ID=MYPC;' +
'Use Encryption for Data=False;' +
'Tag with column collation when possible=False';
Conn.LoginPrompt := False;
Conn.Open;
DataSet.Connection := Conn;
DataSet.CommandText := 'SELECT * FROM MYTABLE';
DataSet.Open;
DataSet.Free;
Conn.Free;
Is there a way to check if a database table is empty without incurring such error?
This error originally occured with an update to MDAC_TYP (to 2.6 from memory). According to an old Borland advisory
"This is a bug in the SQL Server provider. Set
CursorLocation = clUseClient to eliminate the error."
There was a ADOExpress patch available from Borland, but the link doesn't work. Embarcadero now host it here: ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/d5adoupdate2.exe(Thanks for the official link Jeroen!)
I would recommend downloading and installing all patches listed on the Embarcadero site, assuming you can find them.
Download the ADO update for Delphi 5 here: ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/d5adoupdate2.exe
Make sure you also have the regular update installed:
English Enterprise
English Professional
English Standard
There are more updates (Corba, original ADO install) and languages (French, German), but these should get you going.
There also used to be a http://info.borland.com/devsupport/delphi/download_files/zlibupdate.zip, but it is not on the ftpd servers.
--jeroen
It was long time agom but I recall that this problem in Delphi 5 resolves by Delphi update. Early version has serious problems with ADO components
P.S. Also I see that your code uses not typical runtime creation of components and does not use some container like data module or form (not good usually) for visual work with components. Also sometimes useful run simple queries via adoConnection.execute. If you do not use visual components, handling of ADO's Recordset object is much the same as Delphi's AdoDataset.
Since I spent a whole day on this, here is a wrap up of what I did in the end.
Delphi 5 Pro Installation with ADO Express
Uninstall Delphi 5, also deleted installation directory
Install Delphi 5 Pro (I only have a German Delphi Pro edition available)
Install Delphi 5 Pro Update (I used the German update)
Install Delphi 5 ADO Express
Install Delphi 5 ADO Express Update Pack 1
Install Delphi 5 ADO Express Update Pack 2
And the download links (many thanks again Jeroen Wiert Pluimers):
Delphi 5 Pro updates:
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/delphi5/D5ProUpdate.exe
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/delphi5/german/d5proupdate.exe
ADOExpress Update Packs 1 and 2:
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/D5ADOUpgrade.exe
ftp://ftpd.embarcadero.com/pub/delphi/devsupport/updates/adoexpress/d5adoupdate2.exe
And for future reference some screenshots to build the download links (case sensitive):

ReadEventLog() API fails with error code 87 on Windows Server 2008 R2 while reading Application/System/Security event logs from system

I have an MFC application which reads system (i.e. Application/System/Security) event logs on Windows Server 2008 R2 in WOW64 environment. I am facing a problem with std SDK ::ReadEventLog() function in Windows Server 2008 R2. Below I have provided the code snippet, but the same code/API works perfectly in Windows XP WOW64 & x64 environment. Error code '87' refers to "The parameter is incorrect" but according me the parameters which I passed to ::ReadEventLog() function seems to be correct.
[Code]
//BufferSize.
const int BUFFER_SIZE = 1024*10
BYTE l_bBufferSize[BUFFER_SIZE];
EVENTLOGRECORD* l_pEvntLogRecord = NULL;
l_pEvntLogRecord = (EVENTLOGRECORD *) &l_bBufferSize;
::SetLastError(0);
/*
Adjust the 'counter' to read logs. 'l_nReadRecordIndex' is mapped with the list control, e.g. on key down, 'l_nReadRecordIndex' is set as "GetCountPerPage() + 1" this is one case as their are many case.
*/
DWORD l_dwLogCounter = (GetTotalNumberOfRecords() - l_nReadRecordIndex) + 1;
//Read logs as per "nCntToReadRecords".
for(l_dwLogCounter;l_nNoOfRecTobeRead <= nCntToReadRecords;l_dwLogCounter--, l_nNoOfRecTobeRead++)
{
//Get Actual position to read.
if(0 != ::ReadEventLog( m_hEventLogHandle, EVENTLOG_SEEK_READ|EVENTLOG_FORWARDS_READ,
l_dwLogCounter, l_pEvntLogRecord, BUFFER_SIZE,
&l_dwReadBytes, &l_dwNeedBytes))
{
DWORD l_dwErrCode = 0;
l_dwErrCode = ::GetLastError(); //87 is returned
return FALSE
}
}
//Data population code
If any one is aware of similar problem or worked on the similar issue please let me know the solution. Please refer the above code snippet and let me know the following things, a) What are the incorrect parameters. b) Is their any another way to read event logs.
Thanks in advance.
--
Ganesh
It is a bug, check this entry in MS's KB http://support.microsoft.com/kb/177199