Hi, any of you seen similar behavior where CONNECT using Windows authentication requires repeated CONNECT attempts?
What I have:
Setup :: PB 2017 R3, #1858 using ADO.NET with MSSQL.
Code :: See below
SQL Server Authentication :: (using LogId + LogPass) ==> Successful each time
Windows Authentication :: (using TrustedConnection=1) ==> Fails often, but repeating succeeds each time.
...
this.DBMS = 'ADO'
this.DBParm = "NameSpace='System.Data.SqlClient'"
this.DBParm += ",DataSource= ..."
...
this.DBParm += ",TrustedConnection=1"
this.LogId = ''
this.LogPass = ''
...
CONNECT USING this;
if this.SQLCode <> 0 then
...
Error info here is as follows:
this.SQLCode = -1
this.SQLDBCode = 999
this.SQLErrText = System.Exception: Failed to get current user name.
at Sybase.PowerBuilder.Db.Block.SqlBlock.Connect(Object[] input, Dbms& dbms, DBVersion& dbVer, String& user)
at Sybase.PowerBuilder.Db.DbRoutine.Connect(DbDrivers type, Object[] input, Dbms& dbms, DBVersion& dbVer, String& user)
It is the CONNECT statement itself that fails with this error message. No embedded SQL form the PowerBuilder app has executed yet.
First attempt at CONNECT using TrustedConnection has approx 50% success rate.
Second attempt has so far had a 100% success rate. We need first attempt to show same success rate.
Any suggestions greatly appreciated!
/Michael
First hint towards resolution was that deployed EXE seemed to have NO issue while Run-from-IDE failed about every second time it ran.
CAUSE: Missing DISCONNECT in app's Close event. I don't know why I didn't look there but issue on CONNECT seldomly has me look for clues in app.Close.
RESOLUTION: DISCONNECT when app closes.
It seems that when NOT disconnecting, the DB connection is hanging in some undefined state in the context oft he Windows process running the PB IDE. Next CONNECT attempt fails but "crashes"/invalidates the old connection. Therefore next CONNECT attempt succeeds because the old connection has been recycled.
Reason for not seeing this in the deployed EXE is that when that EXE closes, the full Windows process ceases. Hence, next run of the EXE starts a new process and therefore retrieves a fresh connection each time.
CONCLUSION: I (and everyone else) should always follow good design and coding practices: Always DISCONNECT what you CONNECT'ed, always Close what you Open'ed, and always release what you acquired.