I have to check whether the connection between Excel and DB2 has been established using CLI/ODBC driver or not.
For that I plan to write a batch file where I will be calling the excel sheet which in turn will automatically execute a macro which will bring out some dummy data from the sysibm.sysdummy1 table.
I require code with which I can make a connection to my database and check if the connection has been established or not by giving out some success message if the connection was established and a failure message if the connection was not established. (Probably with some explanation where the problem occurred)
You can make an ODBC (or OleDB) connection between a DB2 server and Excel using ADODB (ActiveX Data Objects). See this link for sample connection strings.
This link will show you sample VBA code to use with ADODB to connect to your database:
How To Use ADO with Excel Data from Visual Basic or VBA
EDIT: Here’s some quick and dirty sample code. Replace the
.connectionstring =portion with the proper connection string for your setup.