Community in read only mode June 18 & 19
This community will be set in READ ONLY mode for a while on Tuesday June 18 into Wednesday June 19 while we import content and users from our Micro Focus Forums community site. MORE INFORMATION
sebastienp Absent Member.
Absent Member.
641 views

Connect SQL database without connect statement

Jump to solution

 Hello COBOL community,

 

I actually work on a project with this configuration:

- Visual Studio 2017

- Visual Cobol 4.0

-SQL Server 2014 and SSMS 2017

- Native project

 

I actually have some programs with access to a database. I use a "Connect" statement with parameters such as "Trusted_Connection","Database","factory","server".

My question is: is it possible to include all those parameters with the ADO connection assistant? I tried to configure one but when I use my exec sql statements, I have an SQLcode error.

The goal is to epurate the code of the procedure division and have a COBOL-like program.

Thank you for your answers and have a wonderful week.

 

Sebastien.

Tags (3)
0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

RE: Connect SQL database without connect statement

Jump to solution
I just noticed in your first post that you say you are running a native COBOL project. If you are running the COBOL program as native then the connection you create using the ADO Connection Editor would not apply.
Native programs/projects using ODBC connections and managed .NET programs/projects use ADO connections.

If you are doing a connect from a native application then you would create your DSN using the ODBC Datasource Administrator tool available from the Micro Focus Visual COBOL group on the start menu under Data Tools-->Data Connections. You must choose the version of the tool that matches the bitism of your project either 32-bit for x86 or 64-bit for x64.

The name that you give to your DSN in this tool is the name that you would use in the CONNECT statement.

Example:

EXEC SQL CONNECT TO dsnname END-EXEC

If you are using managed code then you create the DSN using the ADO Connection Editor and likewise use its name in the EXEC SQL CONNECT statement.
0 Likes
6 Replies
Micro Focus Expert
Micro Focus Expert

RE: Connect SQL database without connect statement

Jump to solution
When you click on the Test Connection button in the ADO Connection Editor is the connection successful?
When the connection fails in the EXEC SQL CONNECT statement what is the returned SQLCODE and error message?
0 Likes
sebastienp Absent Member.
Absent Member.

RE: Connect SQL database without connect statement

Jump to solution
Hello M. Glazier, thank you for your answer.

When I test the connection it is successful.

I have the SQLCode "-0019702" with the SQLState" IM001" on all operations (Select, Update, Insert, Delete).

Have a nice day.

Sebastien.
0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Connect SQL database without connect statement

Jump to solution
I just noticed in your first post that you say you are running a native COBOL project. If you are running the COBOL program as native then the connection you create using the ADO Connection Editor would not apply.
Native programs/projects using ODBC connections and managed .NET programs/projects use ADO connections.

If you are doing a connect from a native application then you would create your DSN using the ODBC Datasource Administrator tool available from the Micro Focus Visual COBOL group on the start menu under Data Tools-->Data Connections. You must choose the version of the tool that matches the bitism of your project either 32-bit for x86 or 64-bit for x64.

The name that you give to your DSN in this tool is the name that you would use in the CONNECT statement.

Example:

EXEC SQL CONNECT TO dsnname END-EXEC

If you are using managed code then you create the DSN using the ADO Connection Editor and likewise use its name in the EXEC SQL CONNECT statement.
0 Likes
sebastienp Absent Member.
Absent Member.

RE: Connect SQL database without connect statement

Jump to solution
Thank you very much for this answer M. Glazier. If I've understood, in each case, native or managed, I have to use a connect statement and I can store the parameters of the connection with the ODBC or ADO tool (if I use Native or Managed).

Just for information is there a way to make the MySQL connection "native" when I create a project without this CONNECT statement ?
0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Connect SQL database without connect statement

Jump to solution

It is highly recommended that you do include a CONNECT statement in your program.

There is a directive called SQL(INIT) that can be used in conjunction with the DB and PASS directives that will cause the precompiler to generate this connect code for you but this is dangerous as it exposes your program to having the user credentials appear as clear text within the program itself.

Docs for INIT directive can be found here:

It is not required that you create a connection with a DSN name within one of the editors. This is simply for ease of use and so that the credentials are stored outside of the program. You can use a format 6 CONNECT statement which allows you to pass in a complete connection string instead of using a DSN name.

Examples of this are in the SQL documentation here

sebastienp Absent Member.
Absent Member.

RE: Connect SQL database without connect statement

Jump to solution
Perfect answers, thank you!
0 Likes
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.