Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

How to setup a dynamic SQL ADO connection.

How to setup a dynamic SQL ADO connection.

Problem:

How to setup a dynamic SQL ADO connection.

Resolution:

The code below demonstrates how to populate a String variable with an ADO Connection String.

Use this string variable in the SQL CONNECT statement and the remainder of your SQL statements.

- Start of sample code:

- Create a variable ws-connection-str:
01 ws-connection-str pic x(5000).

- Then in the procedure division:

**** Create an ADO Connection String to establish the ADO.Net Connection.
string 'Data Source=localhost;'
'Initial Catalog=MFTest;'
'Integrated Security=False;'
'Persist Security Info=False;'
'User ID=Thisismyuserid;' *> Specified User ID
'Password=thisismypassword;' *> Specified Password
'Enlist=True;'
'Pooling=True;'
'Min Pool Size=0;'
'Max Pool Size=100;'
'Asynchronous Processing=False;'
'Connection Reset=True;'
'MultipleActiveResultSets=False;'
'Replication=False;'
'Connect Timeout=15;'
'Encrypt=False;'
'TrustServerCertificate=False;'
'Load Balance Timeout=0;'
'Packet Size=8000;'
'Type System Version=Latest;'
'Application Name=".Net SqlClient Data Provider";'
'User Instance=False;'
'Context Connection=False;'
'Transaction Binding="Implicit Unbind";'
'MultipleActiveResultSets=True;'
'factory=System.Data.SqlClient;' *> Factory used to point to the
*> Provider Class we will use.
*> Additional settings documented in Microsoft Help
delimited by size
into ws-connection-str
end-string


Next is the SQL Connect statement code:

EXEC SQL
CONNECT using :ws-connection-str
END-EXEC
IF SQLCODE = 0
DISPLAY "Connected via a Connection String"
DISPLAY "The Connection string could be in code"
EXEC SQL
DISCONNECT CURRENT
END-EXEC
IF SQLCODE NOT = 0
DISPLAY "DISCONNECT ERROR"
STOP RUN
END-IF
END-IF

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2016-04-07 10:38
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.