Hi,
I'm connecting to our SQL Server database from multiple programs. I would like to check at the beginning of each program, if a connection to the SQL Server is already established (by a previously executed program in the same chain). If it is not, I would then like to connect to the database.
Now, I could basically execute some basic SELECT statement and if the return code isn't zero, then it means the connection isn't established. But is there a specific statement in SQL or COBOL, with which I could check the status of the connection?
Cheers,
Raffi
If you are sharing the same connection between multiple programs within a run-unit then you should be using a named connection:
EXEC SQL
CONNECT TO 'SQLODBC32' as connect1
END-EXEC.
When you try to connect to a named connection that is already open you will receive a sqlcode -19707 with message "Duplicate Connection Name".
So if prog2 tries to connect and the connection has not yet been made it will succeed and you will get a sqlcode = 0. If prog2 tries to connect but prog1 already has made the connection you will receive a sqlcode -19707.
Either way you will have a valid connection that prog2 can use.
Thanks.
Hi,
I'm connecting to our SQL Server database from multiple programs. I would like to check at the beginning of each program, if a connection to the SQL Server is already established (by a previously executed program in the same chain). If it is not, I would then like to connect to the database.
Now, I could basically execute some basic SELECT statement and if the return code isn't zero, then it means the connection isn't established. But is there a specific statement in SQL or COBOL, with which I could check the status of the connection?
Cheers,
Raffi
Worked like a charm, thank you!