Call MS SQL stored procedure from ibm system i (as400)

smp2k7
smp2k7 used Ask the Experts™
on
We are purchasing a third party application that requires data to be sent to an MS SQL server from our system i. We can use a stored procedure on the Windows/SQL side to pull the data, however this is an IBM application process that can be run anytime during the day or night so we would have to schedule the procedure to run very frequently to check for data if we want to do it on the Windows side. We would prefer to be able to push the data to the SQL server as a last step of the IBM i application process.

Does anyone have any experience or ideas on how we could trigger the SQL procedure from the IBM? We are on Version 7.1 Mod 0.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
VP Technology / Senior Consultant
Commented:
Lots of ways to handle this:

1) Use JDBC and a Java program on your IBM i to directly connect to the SQL server and insert rows into the target tables.

2) Use JDBC from RPG program using Scott Klements JDBC4R service program:  https://www.scottklement.com/jdbc/

I'll note that using JDBC to do single row inserts for large volumes of data is inefficient.  This works the best when you perform the inserts/updates throughout the day in near real-time.  

If you're doing bulk transfers:

3) You might want to just export the data as a CSV from IBM i (CPYTOIMPF), and then kick off a bulk import script in SQL server.  You could do this on a scheduled basis, or you could remotely invoke the bulk import script from an IBM i program.  For example, you could use the RUNRMTCMD to remotely execute a Windows program or script via the IBM i Access for Windows Incoming Remote Command Service (though I'm not recommending this method any longer due to instability issues when Windows servers are updated to a new service pack or a new OS version).

4) We frequently use ssh to connect from IBM i systems to other IBM i, AIX, Linux, and Unix systems.  Windows doesn't have a native sshd (ssh server), but there are lots of free and commercial sshd servers for Windows available.  ssh allows you to make a command-line connection from the IBM i and securely execute remote commands and perform file transfers to and from the target system.

ssh is a Qshell/PASE command, and has a simple syntax.  Note that for this to work in a a program, you'd need to configure public and private keys to enable password-less authentication, or things get more complicated and you'd have to use something like and Expect script on the IBM i to handle the login using a password (which is insecure anyway).

ssh user1@server1 command1

5) Another relatively easy mechanism to use is to use a folder monitoring solution on Windows.  Use CPYTOIMPF to export your data to a CSV, then transfer the CSV to Windows using the QNTC file system,  Use a folder-monitoring utility on Windows (can just be a simple powershell script that gets started by the scheduler when Windows starts) to watch for a new file and kick off a bulk import script.

If you want more information on any of these options, post back.  

There are also a ton of commercial tools that can help with this, but I think that with just a little effort, it is pretty easy to set up yourself.
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
smp2k7, do you still need help on this question?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial