Skip to main content

Hi, what about the SQL Option to set the application name - any restrictions with Microsoft SQL Server?

I tried the following:

exec sql set option APPLICATION "MyAppName" end-exec

exec sql connect to :db-alias  user :user-passw end-exec

The connect works as usual but APP_NAME() in SQL Server is not affected, it is empty.

Windows 7 Professional, Net Express 5.1 (Version 5.104.0083), Application build as 32-Bit, SQL Server 2012, ODBC driver standard SQL Server

Regards, Torsten

 

Hi, what about the SQL Option to set the application name - any restrictions with Microsoft SQL Server?

I tried the following:

exec sql set option APPLICATION "MyAppName" end-exec

exec sql connect to :db-alias  user :user-passw end-exec

The connect works as usual but APP_NAME() in SQL Server is not affected, it is empty.

Windows 7 Professional, Net Express 5.1 (Version 5.104.0083), Application build as 32-Bit, SQL Server 2012, ODBC driver standard SQL Server

Regards, Torsten

 

Hi Torsten,

If you use code such as:-

         STRING "DRIVER={SQL Server};"

                         DELIMITED BY SIZE

                        ";DATABASE=TestDB"

                        ";SERVER=nwb-dbsqlserv"

                        ";AutoTranslate=no" DELIMITED BY SPACE

                        ";Trusted_Connection=yes;"

                        "app=MyTestApplication"

                         DELIMITED BY SIZE

                        INTO WS-CONNECTIONSTRING

         END-STRING

        EXEC SQL CONNECT USING :WS-CONNECTIONSTRING END-EXEC.

          if sqlcode not = 0

               display "Error: not connected"

               display sqlcode

               display sqlerrmc

               stop run

          end-if

          EXEC SQL

               SELECT APP_NAME()

               INTO  :ws-app-name

          END-EXEC

you can specify this on the connection string.

Ii general if you want to use a SET SQL Server statement you would normally use EXEC SQL EXECUTE IMMEDIATE :ws-mysql to run it.

Regards

David


Hi, what about the SQL Option to set the application name - any restrictions with Microsoft SQL Server?

I tried the following:

exec sql set option APPLICATION "MyAppName" end-exec

exec sql connect to :db-alias  user :user-passw end-exec

The connect works as usual but APP_NAME() in SQL Server is not affected, it is empty.

Windows 7 Professional, Net Express 5.1 (Version 5.104.0083), Application build as 32-Bit, SQL Server 2012, ODBC driver standard SQL Server

Regards, Torsten

 

Actually the original method that you were using EXEC SQL SET OPTION APPLICATION "appname" will work but it requires that you set on the directive SQL(TARGETDB=MSSQLSERVER).

This option is specific to SQL Server and has to be set before the connection is opened. If you do not set TARGETDB=MSSQLSERVER then the SET will be ignored.


Hi, what about the SQL Option to set the application name - any restrictions with Microsoft SQL Server?

I tried the following:

exec sql set option APPLICATION "MyAppName" end-exec

exec sql connect to :db-alias  user :user-passw end-exec

The connect works as usual but APP_NAME() in SQL Server is not affected, it is empty.

Windows 7 Professional, Net Express 5.1 (Version 5.104.0083), Application build as 32-Bit, SQL Server 2012, ODBC driver standard SQL Server

Regards, Torsten

 

Thanks for your answer, David.

But i'm not using a connection string. Chris found out the solution: TARGETDB=MSSQLSERVER has to be set.

Regards, Torsten


Hi, what about the SQL Option to set the application name - any restrictions with Microsoft SQL Server?

I tried the following:

exec sql set option APPLICATION "MyAppName" end-exec

exec sql connect to :db-alias  user :user-passw end-exec

The connect works as usual but APP_NAME() in SQL Server is not affected, it is empty.

Windows 7 Professional, Net Express 5.1 (Version 5.104.0083), Application build as 32-Bit, SQL Server 2012, ODBC driver standard SQL Server

Regards, Torsten

 

Thanks Chris,

that's what's causing it.

Regards, Torsten