PDA

View Full Version : cConnection.pkg – pbLoginOnOpen



Clive Richmond
24-Feb-2017, 05:45 AM
I am still evaluating the possibility of setting this property to false and pleased to see it is no longer a design time only property.

Some of our Open As usage can be changed to using a connection id string but there are several other places where this is more difficult. Therefore, I am temporarily setting pbLoginOnOpen to true and resetting it once the task has been completed.

However, I noticed if I then open another table using the same Open As syntax I don’t get a “Can’t open table. Not logged into ...” My question is this behaviour expected and why, or should it fail?


// Create the open as string format which should resemble something like this:
// "{driver}:dbo#{table}@{connection string}|options|intfile={table.int}"
// "MSSQLDRV:dbo#customer@SERVER=.\SQLEXPRESS;DATABASE =Order Entry Flx2SQL;trusted_connection=yes|options|intfile=C:\ DataFlex 19.0 Examples\Order Entry\Data\customer.int"

Move "customer" To sTable
Get psDataPath Of (phoWorkspace(ghoApplication)) To sDataPath
If (Right(sDataPath, 1) <> '\') Move (sDataPath+'\') To sDataPath
Move (sDataPath+sTable+".int") To sIntFile
Move (SFormat("%1:dbo#%2@%3|options|intfile=%4", ltConnectionId.sDriver, sTable, ltConnectionId.sConnectionString, sIntFile)) To sTableConnStr

Move 0 To hSQLTable
Get_Attribute DF_FILE_NEXT_EMPTY Of hSQLTable To hSQLTable

Get pbLoginOnOpen Of ghoConnection To bOpen // reports false
Set pbLoginOnOpen Of ghoConnection To True
Open sTableConnStr As hSQLTable
Move WindowIndex To WindowIndex
Close hSQLTable
Set pbLoginOnOpen Of ghoConnection To bOpen
Get pbLoginOnOpen Of ghoConnection To bOpen // reports false

// Should this open the table or should it fail?
Get_Attribute DF_FILE_NEXT_EMPTY Of hSQLTable To hSQLTable

Move (Replaces("customer", sTableConnStr, "vendor")) To sTableConnStr
Open sTableConnStr As hSQLTable
Move WindowIndex To WindowIndex
Close hSQLTable

John Tuohy
24-Feb-2017, 03:32 PM
I would expect it to raise an error if you are not logged in. However, maybe you are now logged in. There still might be a connection from the prior login/open. If that were the case, you'd not get an error. Is that a possibility?

-John

Clive Richmond
27-Feb-2017, 02:40 AM
I would expect it to raise an error if you are not logged in. However, maybe you are now logged in. There still might be a connection from the prior login/open. If that were the case, you'd not get an error. Is that a possibility?

Yes. This is the same old issue I have struggled with before. While they are physically the same server and database etc logically they are different to DataFlex.

I added some debug statements to enumerate the connected server names. I can see there is a connection via an id, created when the application loaded, and a connection via a full string, created during the open as. The bit I had forgotten to do was logout of the ‘open as’ server. If I do I get to see the error.


Connections:
Before Open As / pbLoginOnOpen=F
databases:
- DFCONNID=ORDER-ENTRY-01
After Open As / pbLoginOnOpen=T
databases:
- SERVER=.\SQLEXPRESS;DATABASE=Order Entry 01;trusted_connection=yes
- DFCONNID=ORDER-ENTRY-01
After Close Table / pbLoginOnOpen=F
databases:
- SERVER=.\SQLEXPRESS;DATABASE=Order Entry 01;trusted_connection=yes
- DFCONNID=ORDER-ENTRY-01
After Logout
databases:
- DFCONNID=ORDER-ENTRY-01


I now understand what’s happening and why. Although it I probably won’t stop me repeating the same mistake :).