Hello,
We have a problem with MSOLEDBSQL driver (v19.2.0.0) when we use a temporary table.
If we create a temporary table with the following syntax :
String ls_SQL
ls_SQL = "CREATE TABLE #tmp_WHO ( " + &
"spid smallint, ecid smallint, status nchar(30), loginame nchar(128), hostname nchar(128), " + &
"blk char(5), dbname nchar(128), cmd nchar(26), request_id int )"
EXECUTE IMMEDIATE :ls_SQL USING MyTransaction;
Insert data in the table with the following commands :
ls_SQL = "INSERT INTO #tmp_WHO EXEC('sp_who')"
EXECUTE IMMEDIATE :ls_SQL USING MyTransaction;
And use the SyntaxFromSQL function :
String ls_Select
String ls_Presentation
String ls_Errors
ls_Select = "SELECT spid, ecid, status, loginame, hostname, blk, dbname, cmd " + &
"FROM #tmp_WHO WHERE dbname = '" + MyTransaction.Database + "' "
ls_Presentation = "style(type=grid) " + &
"column(font.face='Arial' font.height=-8 font.family=2 font.pitch=2 font.weight=400) " + &
"text(font.face='Arial' font.height=-8 font.family=2 font.pitch=2 font.weight=700 background.mode=0 background.color=33541277)"
MyTransaction.SyntaxFromSQL( ls_Select, ls_Presentation, ls_Errors )
ls_Errors returns an empty string and I assume they are no errors.
BUT, Immediately after the SyntaxFromSQL if we launch a simple query, the SQLCode from MyTransaction returns -1
For example, if I want to see if our database is compatible with the version of our application :
ls_SQL = "SELECT 1 WHERE EXISTS (SELECT 1 FROM VERSION WHERE NVERSION = 16 AND NRELEASE = 0 AND NRELEASEMINOR = 0)"
EXECUTE IMMEDIATE :ls_SQL USING MyTransaction;
Here are the error codes returned by the transaction :SqlCode = -1
SqlDbCode = 208
SqlErrText = SQLSTATE = 42S02
Microsoft OLE DB Driver 19 for SQL Server
Invalid object name 'VERSION'.
When we use the old drivers (OLEDB or SQLNCLI), it works proprerly.
If we remove the # character from the name of the temporary table, it works without issues.
Have the standards changed with the MSOLEDBSQL driver ?
I checked, and the transaction is still connected to the database.
Here is the dbparm of the transaction :MyTransaction.dbparm :
PROVIDER='MSOLEDBSQL19',OJSyntax='ANSI',CommitOnDisconnect='No',DelimitIdentifier='No',PBNoCatalog='Yes',DisableBind=1,StaticBind=0,DATASOURCE='MyServer\SQL2019',PROVIDERSTRING='Database=MyDatabase;APP=MyApp',TrimSpaces=1,Encrypt=1,TrustServerCertificate=1,DateFormat='\''dd/mm/yyyy\''',DateTimeFormat='\''dd/mm/yyyy hh:mm:ss.fff\''',DecimalSeparator=','
That is a definite DB driver bug. I've been using #<TableName> temporary tables in ASE & SS for decades from PB Apps. Please open a Support Ticket for this issue.
In the meantime, I wonder if using a 2nd Transaction Object connected to SS via SNC just for temporary table processing might work OK for your App (until Engineering can look into this issue deeper)?
Regards ... Chris