Still can't call as400 program from VB.NET?

S

Scott Johnson

Hi

I have been pulling my hair out for the past week trying to call a program
(or a query, or CL etc) on an iSeries (as400) from VB.NET and I just can't
get it. Jay had written me back and told me to treat it like a
StoredProcedure, which I will include a sample of my error-generating code
below, but it still doesn't work.

Does anyone have a sample of code they could share to show me the light or
have any suggestions?

'** Code Sample Generates
Dim cn As New System.Data.Odbc.OdbcConnection
cn.ConnectionString = "DSN=SA;UID=XXXX;PWD=XXXX;"
cn.Open()
Dim cmd As New System.Data.Odbc.OdbcCommand
cmd.Connection = cn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "{{ RUNQRY QRY(SCOOTER/SAJTEST) }}"
cmd.ExecuteNonQuery()
'** Cleanup, etc
MsgBox("done")

I get an unhandled exception of System.Data.Odbc.OdbcException in
system.data.dll and additional information: System Error on the line
ExecuteNonQuery. SA is a DSN to my as400 using iSeries Access ODBC driver
version 9.00.05.00 for V5R2M0

Thanks for your help!
--Scott
 
M

Marina

You need to put this in a try catch block and look at the exception object.
System error is what you get in the debugger.
 
J

Jay B. Harlow [MVP - Outlook]

Scott,
In addition to Marina's comments:
cmd.CommandText = "{{ RUNQRY QRY(SCOOTER/SAJTEST) }}"

It appears that you are attempting to execute a command. You cannot execute
a command per se, you need to CALL a program!

You can use the QCMDEXC program to execute a command.

For an example of executing a command, check out the following sample:
http://www.sqlthing.com/Resources/StartandStopDebug.html

Note the above sample also shows how to execute a program!

Hope this helps
Jay
 
S

Scott Johnson

I got it! Thank you both very much!!!!


Jay B. Harlow said:
Scott,
In addition to Marina's comments:


It appears that you are attempting to execute a command. You cannot execute
a command per se, you need to CALL a program!

You can use the QCMDEXC program to execute a command.

For an example of executing a command, check out the following sample:
http://www.sqlthing.com/Resources/StartandStopDebug.html

Note the above sample also shows how to execute a program!

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top