How to debug an intemittent error using Progress OpenEdge database - sql

I have a program that fails intermittently in a complex query.
The error reads:
System.Data.SqlClient.SqlException: Cannot fetch a row from OLE DB provider "MSDASQL" for linked server "LinkedServer".
The query looks like this:
SELECT Replace([JOB-NO],'M0','') as KeyTaskID,
dbo.SFGET_UniqueTaskID([CLIENT-CODE],Replace([JOB-NO], 'M0', ''), 0, [TRADE-CODE]) AS HMSUniqueTaskID,
[LATEST-PRIORITY] AS PriorityCode,
[KeyProperty] AS KeyProperty,
Replace([JOB-NO],'M0','') AS KeyJob,
[JOB-TYPE] as TaskSubType,
CONVERT(varchar(6),[MAINT-OFFICER]) AS Officer,
LEFT(FORENAME + ' ' + SURNAME, 50) AS OfficerName,
[JOB-NO] + ' ' + LEFT(RTRIM(REPLACE([TEXT-LINE], ';', CHAR(13))), 480) AS Description,
dbo.SFGET_FormattedDate([TARGET-DATE],0) AS DueDateTime,
[CURRENT-STAGE-CODE] AS CurrentStageCode
FROM openquery(LinkedServer, '
SELECT DISTINCT
"RM-JOB"."JOB-NO",
"RM-JOB"."CLIENT-CODE",
"RM-JOB"."LATEST-PRIORITY",
"RM-JOB"."TRADE-CODE",
"RM-JOB"."JOB-TYPE",
"RM-JOB"."TARGET-DATE",
"RM-JOB"."MAINT-OFFICER",
"RM-JOB"."TEXT-LINE",
"RM-JOB"."CURRENT-STAGE-CODE",
"RM-JOB"."PLACE-REF",
"IH_OFFICER".FORENAME,
"IH_OFFICER".SURNAME
FROM "PUB"."RM-JOB"
LEFT OUTER JOIN "PUB"."IH_OFFICER"
ON ("IH_OFFICER"."OFFICER-CODE" = "RM-JOB"."MAINT-OFFICER")
WHERE "RM-JOB"."JOB-TYPE" = ''GASS''
AND "RM-JOB"."JOB-STATUS" = 06
AND "RM-JOB"."CONTRACTOR" = ''NWH001'' ') as ibsTasks
INNER JOIN [SVSExtract].[dbo].Property prop
ON ibsTasks.[PLACE-REF] = prop.UserCode
I have been testing it manually using SQL Server Management Studio. It occassionally fails but it mainly works OK.
I am at a loss as to how I can debug an error that I cannot reproduce at will.
Any suggestions?

I'm not that proficient in SqlClients and Progress myself but: the Progress Knowledgebase might give you a solution!
This entry for instance describes a similar error, even if the version mentioned might be older than the one you use? (Always post version when asking about OpenEdge - there's lots of older installations out there and Progress has evolved quite a bit during the last couple of years).
The Knowledgebase is honestly best searched using Google:
Search for instance: site:knowledgebase.progress.com MSDASQL and you'll get 48 results.

Related

PHP PDO MSSQL - Aborting DB transaction in query which raisses error with severity 0 (warnings)

I am creating web app in Laravel which connects to MSSQL DB (using PDO) and i'm stuck with a issue when running query (UPDATE in my case)
update dba.[vl_zahlavi] set [xcmd] = ' AFTERCOMMIT', [vl_zahlavi].[ts] = '2023-01-10 14:16:06.505' where [doklad] = '23VLTU0100000001'
which raises error with severity 0 within update trigger (used for sending progress bar information to client). Trigger is created within information system, so I'm not able to disable this functionality.
select #progress_count = convert(int/*BY*/,#akt_pocet), #progress_current = 0, #progress_dt_o_skl_o_skl_gen_poh_prub = DateAdd(ms, -1000, GetDate())
select #progress_arg = '#SQL_PROGRESS=O_SKL,O_SKL_GEN_POH_PRUB,' + convert(varchar(255)/*BY*/, ##nestlevel) + ',OPEN,' + convert(varchar(255)/*BY*/, #progress_count) + ';'
RAISERROR ('%s', 0, 1, #progress_arg) WITH NOWAIT
Problem is, that PHP client send abort and transaction is automatically rolled back. When I comment this section of code (or change severity to 16), everything works as expected. Bellow is printscreen from SQL server profiler.
printscreen
Is PDO able to catch user error messages?
Thank you in advance.
I have tried to change DB sets and PDO options, but without success.

How to reproduce with a manual query: [Amazon](500310) Invalid operation: failed to find conversion function from "unknown" to integer;

I recently added a maven dependency to a Dropwizard project:
<dependency>
<groupId>com.amazon.redshift</groupId>
<artifactId>redshift-jdbc42-no-awssdk</artifactId>
<version>1.2.45.1069</version>
</dependency>
which is replacing the org.postgresql.Driver previously used, and since then some of my queries are returning
! Causing: org.skife.jdbi.v2.exceptions.UnableToCreateStatementException: java.sql.SQLException: [Amazon](500310) Invalid operation: failed to find conversion function from "unknown" to integer;
I suspect I might have dozens of queries that will need adapting to work with the new driver.
Because I don't want to have to restart my server every time I want to test whether a change to a query fixes the problem, I want to run the queries manually against the Redshift DB, so that I can quickly identify the part of the query that needs fixing.
My problem: I cannot reproduce the error when running the query manually from inside an IntelliJ DB Console. I even downloaded the JAR of the Amazon Redshift Driver from https://docs.aws.amazon.com/redshift/latest/mgmt/configure-jdbc-connection.html (I downloaded this one: https://s3.amazonaws.com/redshift-downloads/drivers/jdbc/1.2.45.1069/RedshiftJDBC42-no-awssdk-1.2.45.1069.jar) and used it to set up a new DB connection in IntelliJ. But still, running the exact same query manually from the IntelliJ DB Console won't give me the error.
Can anyone think of what configuration might be causing the query to give an error when run by the server compared to running it manually from the Console ? And how to get it to either stop throwing the exception on the server or start causing the same error when run in a Console ?
I'm assuming the issue lies somewhere between JDBI and the Amazon Redshift Driver. In any case, here's a fix that solved the problem for now:
For a query like this:
//language=PostgreSQL
public static final String MY_QUERY = "" +
"WITH my_table(someid, groupname) AS (\n" +
" SELECT :someId, :groupName\n" +
")\n" +
"SELECT 'something'\n" +
"FROM my_table mt\n" +
"FULL OUTER JOIN another_table at ON at.accountid = mt.someid AND at.groupname = mt.groupname";
Adding \\:\\:int got rid of the error:
//language=PostgreSQL
public static final String MY_QUERY = "" +
"WITH my_table(someid, groupname) AS (\n" +
" SELECT :someId\\:\\:int, :groupName\\:\\:text\n" +
")\n" +
"SELECT 'something'\n" +
"FROM my_table mt\n" +
"FULL OUTER JOIN another_table at ON at.accountid = mt.someid AND at.groupname = mt.groupname";

SQL looking for a part number ending in '~0000'

I am trying to find records ending in ~0000 such as ABC~0000
but everything I try doesn't seem to work. Some examples:
and left (mfr_part_number, 4) = 'ABC~' -- finds nothing
and left (mfr_part_number, 3) = 'ABC' -- finds stuff
AND RIGHT(MFR_PART_NUMBER, 4) = '0000' -- finds nothing
AND RIGHT(MFR_PART_NUMBER, 5) = '~0000' -- finds nothing
and DbFunctions.Like(MFR_PART_NUMBER,'%0000') -- suggested elsewhere, but not recognized in MSSMS.
I am using:
SQL Server Management Studio 15.0.18206.0
Microsoft Analysis Services Client Tools 15.0.1567.0
Microsoft Data Access Components (MDAC) 10.0.18362.1
Microsoft MSXML 3.0 6.0
Microsoft .NET Framework 4.0.30319.42000
Operating System 10.0.18363
Thanks!
Are you using all of those AND statements in your WHERE clause? If so, that would cause nothing to return if there's no data that matches all criteria.
Try
SELECT column1, column2...
FROM yourdb
WHERE MFR_PART_NUMBER LIKE '%0000'

SQL Server OLEDB error with no details

I have a SQL Server Agent job running, which uses a stored procedure to do several operations, then exports some data to an xls spreadsheet and emails that spreadsheet. Most of the time it works, but several times a month the job fails with the error:
OLE DB provider 'Microsoft.Jet.OLEDB.4.0' reported an error. The provider did not give any information about the error. [SQLSTATE 42000] (Error 7399). The step failed.
Thanks, Microsoft, for the detailed error message. Anyway, the short term fix is usually to simply re-run the job. Usually this works, but in rarer cases it does not, and I must restart the SQL Server instance.
Here is how my code interacts with OLEDB:
Insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 5.0;Database=\\Excel\POStatus\POStatus.xls;',
'SELECT * FROM [POStatus$]')
Select --Tons of columns with tons of math and functions
FROM --5 tables joined together (left joins)
WHERE -- Tons of where conditions
Order by --Case statement for custom sorting
Set #vCommand = 'copy \\Excel\POStatus\POStatus.xls \\Excel\POStatus\POStatus_' + #vDate + '.xls'
EXEC master..xp_cmdshell #vCommand , NO_OUTPUT
... omitted for brevity...
Set #nvSubject = ' POStatus ' + #vDate
Set #nvMessage = ' This is an automated message, please respond to the IS department, thank you '
Set #nvMessage = #nvMessage + char(13) + char(10)
Set #nvAttachments = '\\Excel\POStatus\POStatus_' + #vDate + '.xls'
Exec master..xp_sendmail
#recipients = #nvRecipients , #copy_recipients = #nvCopy_recipients ,
#subject = #nvSubject , #message = #nvMessage ,
#query = #nvQuery , #width = #iWidth , #attachments = #nvAttachments
So, what is the cause of this, and how can I prevent it?
When you call OPENROWSET, it load the DLL for OLEDB provider for Excel. These operations happens inside the SQL Server Stack memory. When a lot of call to older DLL (ActiveX/COM) are made, it's not impossible that your stack might get full. You can resolve this in 2 ways:
1) You make these operations outside a TSQL code. You can use a SSIS package for example but you have to change your code not to use OPENROWSET. You can use the DTS Wizard to do most of the job. This is my personnal recommandation !
2) You can also set SQL Server to have a bigger memory Stack by using the -g command parameter. I think 256 MB is the default and you can set it to 512. To do that you need to open the SQL Server Configuration Manager. Depending on your version, you should have a place to change the "Startup Parameters"

qt mysql query giving different result on different machine

Following code works on my pc but gives error on other pc's. how is it possible to run this successfully on all machines.
QSqlQuery query;
QString queryString = "SELECT * FROM " + parameter3->toAscii() + " WHERE " + parameter1->toAscii() + " = \"" + parameter2->toAscii() + "\"";
bool retX = query.exec(queryString);
What pre requisite should be fulfilled for this to run on any pc
In troubleshooting, if you isolate your query and it returns the result you anticipated ( such as you have done utilizing qt creator to verify the query returns a result of true), the next step would be to take a close look at your code and verify that you are passing the proper parameters into the query for execution.
I have a virgin machine I utilize for this purpose. I am a software engineer by trade and I am fully aware that i have a ton of software installed on my PC which the common user may/will not have installed. So the virgin allows me to test the code in stand-alone form.
I suggest implementing a message box prior to the execution of your query which shows the query to be executed. This will verify the query is correct on the "other machines".
Certain dll's were needed. in my case qtguid4.dll, qtcored4.dll and qtsqld4.dll. There was a size difference. Once matched it worked on a pc. However, on other pc's i still get an error "The application failed to initialize 0xc000007b ....."
How is it possible to make an application run.
Brgds,
kNish