HI,
I am trying to figure out how to write a C# program to add parameter's "A" and "B" and return "C" in the following code:
I get an error at the commnd.ExecuteNonQuery(); statement below. The error states:
X2 Provider Error: <ExecuteHelper Failed>
X2 Provider Error: <Internal Error: Failed to get the IProc Interface>
The provider works with ADO.Net according to the developer.
Here's the code I have so far: - using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data.OleDb;
-
using System.Drawing;
-
using System.Linq;
-
using System.Text;
-
using System.Data;
-
using System.Windows.Forms;
-
-
-
namespace ADP_API
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
-
private void button1_Click(object sender, EventArgs e)
-
{
-
string constr = "provider=ADPProv.ADPProv.1;host=" + Host.Text;
-
constr = constr + ";product=" + Product.Text;
-
constr = constr + ";server=" + Server.Text;
-
constr = constr + ";password=" + Password.Text;
-
constr = constr + ";pooling=TRUE";
-
-
OleDbConnection con = new OleDbConnection(constr);
-
-
con.Open();
-
-
OleDbCommand commnd = new OleDbCommand();
-
commnd.Connection = con;
-
commnd.CommandType = CommandType.StoredProcedure;
-
commnd.CommandText = "proc=Addition";
-
-
OleDbParameter paramReturnValue = new OleDbParameter();
-
paramReturnValue.ParameterName = "C";
-
paramReturnValue.OleDbType = OleDbType.Integer;
-
paramReturnValue.Direction = ParameterDirection.Output;
-
-
OleDbParameter paramA = new OleDbParameter();
-
paramA.ParameterName = "A";
-
paramA.OleDbType = OleDbType.Integer;
-
paramA.Direction = ParameterDirection.Input;
-
paramA.Value = var1.Text;
-
-
OleDbParameter paramB = new OleDbParameter();
-
paramB.ParameterName = "B";
-
paramB.OleDbType = OleDbType.Integer;
-
paramB.Direction = ParameterDirection.Input;
-
paramB.Value = var2.Text;
-
-
commnd.Parameters.Add(paramReturnValue); commnd.Parameters.Add(paramA); // parameter 1
-
commnd.Parameters.Add(paramB); // parameter 2
-
-
-
-
commnd.ExecuteNonQuery();
-
-
int returnValue = (int)commnd.Parameters["C"].Value;
-
-
Output.Items.Add(returnValue);
-
-
con.Close();
-
-
}
-
}
-
}
-
Thanks,
John
14 7955
OK I got it to return a value in my listbox with the following code but with 6 and 5 put in for var1 and var2 respectively I get a zero in the list box. Any ideas why commnd.Parameters["C"].Value is null? Could it be that ExecuteNonQuery is wrong for this??
Thanks
Here's my new more successful code: - using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data.OleDb;
-
using System.Drawing;
-
using System.Linq;
-
using System.Text;
-
using System.Data;
-
using System.Windows.Forms;
-
-
-
namespace ADP_API_Practice
-
{
-
public partial class Form1 : Form
-
{
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
-
private void button1_Click(object sender, EventArgs e)
-
{
-
string constr = "provider=ADPProv.ADPProv.1;host=" + Host.Text;
-
constr = constr + ";product=" + Product.Text;
-
constr = constr + ";server=" + Server.Text;
-
constr = constr + ";password=" + Password.Text;
-
constr = constr + ";pooling=TRUE";
-
-
OleDbConnection con = new OleDbConnection(constr);
-
-
con.Open();
-
-
OleDbCommand commnd = new OleDbCommand();
-
commnd.Connection = con;
-
commnd.CommandType = CommandType.StoredProcedure;
-
commnd.CommandText = "group=ADMIN;object=Procs;name=Addition";
-
-
OleDbParameter paramA = new OleDbParameter();
-
paramA.ParameterName = "A";
-
paramA.OleDbType = OleDbType.Integer;
-
paramA.Direction = ParameterDirection.Input;
-
paramA.Value = Int32.Parse(var1.Text);
-
-
OleDbParameter paramB = new OleDbParameter();
-
paramB.ParameterName = "B";
-
paramB.OleDbType = OleDbType.Integer;
-
paramB.Direction = ParameterDirection.Input;
-
paramB.Value = Int32.Parse(var2.Text);
-
-
OleDbParameter paramReturnValue = new OleDbParameter();
-
paramReturnValue.ParameterName = "C";
-
paramReturnValue.OleDbType = OleDbType.Integer;
-
paramReturnValue.Direction = ParameterDirection.ReturnValue;
-
-
commnd.Parameters.Add(paramA);
-
commnd.Parameters.Add(paramB);
-
commnd.Parameters.Add(paramReturnValue);
-
-
commnd.ExecuteNonQuery();
-
-
int returnValue = (int)commnd.Parameters["C"].Value;
-
-
Output.Items.Add(returnValue);
-
-
con.Close();
-
-
}
-
}
-
}
I noticed in your first post, you added the return parameter to the parameter collection first, but you tagged it incorrectly as ParameterDirection.Output.
In the second post, you tagged it correctly as ParameterDirection.ReturnValue, but you add it to the collection last.
I believe MSDN states that ReturnValue parameters always need to be added to the ParameterCollection first, so try that again.
Also, not seeing your actual stored procedure, make sure it is indeed a ReturnValue and not an output paramater.
In SqlServer, for example, a ReturnValue is returned by the sql "RETURN" statement.
An output parameter is declared in the procedure definition, and the parameter is filled during the procedure. There may or may not also be a RETURN statement, but it is unrelated to the output parameter.
Also, SqlServer at least, has an implicit return value of 0 when successful, whether you declare it or not, so that may explain why you get a 0 in your text box.
Hi and thank you for your response. You are right it was an Output Parameter. I still only get a 0 when I make that change though.
I'm not understanding your last paragraph about 0 being returned when successful.
I had a look around on the server and there is another object called AdditionParams where I found all the attribute of each parameter and there is a place for their value. It looks like the Addition proc might look to that object for the A and B values and return the C value there??
Knowing that, how would I approach this? Write to the AdditionParams object, run the proc with no added params and read the C value???
Thanks for your help.
Can you post the sql for both procedures?
Please enclose the procedures in CODE tags. Also, you can cut out any irrelevant statements if the procedures are long. Basically, we need to look at the procedure declarations (usually at the beginning), any calls to other procedures, and any statements that set the parameters.
Just for clarification, what database are you using?
What I mean by SQL Server returns an implicit zero is that if the procedure completes without error, and you do not have a RETURN statement, SQL Server implicitly returns a value of 0 to indicate success. So, even if you do not specify a RETURN statement in your sql procedure, if you create a Parameter with a ReturnValue direction in ADO.Net, it will be filled with a zero value.
The only reason I pointed that out is that if you mistakenly assign a ReturnValue parameter to your collection instead of an output parameter, and the value in your TextBox is always zero, it might be because it it simply reading the implicit return value of zero.
I really appreciate your help.
I don't have access to the procedures unfortunately. I just have API documentation which is based on the old ADO. The procs are in ENGLISH a query language used on the PICK OS.
The database is on a PICK system with multivariant fields and subvalues etc which is why I have to use the ADP provider. ADP is a computer system for car dealerships and they are very protective of their database. I have access to a training database.
I work for a chain of dealerships and I have to get proficient in the API before they will allow us access to our own data. The ADP chief software engineer really doesn't want to work with ADO.Net. Everytime I ask him a question he sends VB6 code and says it should work.I suppose I could work in VB6. Apparently I am not converting correctly to C# and .Net.
Here's his latest:
"John,
If it returns zero, then it is not working correctly (unless you added 0 + 0).
You do not need to give it the group or object values.
I made a VB 6 version of the Addition tester in a bare bones code to make it easier to see (using the ADO Tester code as a guide) and tested it against the TRAIN36 product. This should help you determine where your coding issues are.
Here is my code – I highlighted the important sections of code. Yellow is supporting code and blue is the critical code in the API call itself."
Again thanks for your help.
I feel sorry for your situation, you are working against a black box.
Looking at his sample code, I would conclude he is calling "proc=Addition" directly, so I don't think you should change to the "AdditionParams" object.
From an ADO.Net perspective, your code looks like it should be correct. I do not see any "obvious" errors. Sometimes connections strings are different between legacy ADO and ADO.Net, but the connection would not be open if the connection string you are using is incorrect. And looking at his legacy connection code, I do not see any obvious reason why the ADO.Net should not work. At a minimum, it would throw some "Provider not found" error or such if there was an obvious showstopper.
- When you say you tried with "6" and "5", did you hard code those in? And did you try to display or view the result using the debugger to examime parameter "C" directly instead of relying on the form?
- I noticed his string uses "productpassword"; did you try keeping that instead of just "password"? Also, are you sure that by adding "group=ADMIN" you are addressing the correct stored procedure?
This is tough. I guess you can try using the debugger and making sure the connection is truly opened (although it would throw an exception if it wasn't) and then perhaps put a try/catch around the ExecuteNonQuery statement to make sure it is truly executing.
I am at a loss. I have never heard of this PICK database. One last try might be to use the System.Data.Odbc library instead of OleDb...but I'm just shooting in the dark.
Also...are there any tables you know about where you can test a very simple "Select" statement, just to confirm the database is capable of returning data?
mmm...I came across one (count 'em - one) post regarding this ADPProv Provider;
This might even be your post, as it is so similar. However, I see one difference:
I figured it out. See the underlined changes below. I should not have used TableDirect but Text and then any string is cool.
- private void button1_Click(object sender, EventArgs e)
-
{
-
string constr = "provider=ADPProv.ADPProv.1;host=" + Host.Text;
-
constr = constr + ";product=" + Product.Text;
-
constr = constr + ";server=" + Server.Text;
-
constr = constr + ";password=" + Password.Text;
-
constr = constr + ";pooling=TRUE";
-
-
OleDbConnection con = new OleDbConnection(constr);
-
-
OleDbCommand command = new OleDbCommand();
-
command.CommandType = System.Data.CommandType.Text;
-
command.CommandText = "group=ADMIN;object=Object";
-
command.Connection = con;
-
con.Open();
-
-
OleDbDataReader reader = command.ExecuteReader();
-
-
int columnCount = reader.FieldCount;
-
while (reader.Read())
-
{
-
for (int i = 0; i < columnCount; i++)
-
{
-
Output.Items.Add(reader.GetName(i).ToString()+"= " + reader.GetValue(i).ToString());
-
}
-
}
-
-
reader.Close();
-
con.Close();
-
}
Did you try setting your CommandType to "Text" instead of "StoredProcedure"?
This PICK thingy may not have any concept of stored procedure.
These are great comments. I will try each one over the weekend.
That was my post on experts-exchange I believe when I needed help getting the connection to work and I solved it myself. But this is kind of crazy. I may just skip this exercise and move on.
If I ever needed to create a stored proc and use it I think I could get it to work. Just working against an unknown is hard.
I really appreciate you talking this through with me. The rest of the net is not only silent on PICK but they don't respond much on non SQL ADO.Net
I'll post soon. Thanks again.
I tried all your suggestions and none of them totally fixed the code. However I think I am now on the right track. Maybe you can confirm my thinking and the direction I think I need to pursue.
I ran a bunch of different commnd.CommandType.Text values and some gave me no error (but 0 still) and some gave me an error. I think "no error" is a dead end and I also think the IProc Interface error is the right direction. I believe this means that .Net is saying "Ok we are calling a Stored Procedure but I can't get the provider to hook me up."
As opposed to paramC is always zero because it is set to zero and never is acted on because .Net sees no procedure request????
Here's my Error list: These did not give errors:
commnd.CommandText = "group=ADMIN;object=AdditionParams;name=Additi on";
commnd.CommandText = "group=ADMIN;object=Procs;name=Addition";
commnd.CommandText = "group=ADMIN;object=Procs;methodname=Addition" ; These did give me errors:
commnd.CommandText = "group=ADMIN;MethodName=Addition"; X2Provider Error <Object not found>
commnd.CommandText = "group=ADMIN;object=Procs;proc=Addition"; X2Provider Error<Internal Error:Failed to get the IProc Interface>
commnd.CommandText = "proc=Addition"; X2Provider Error <Internal Error:Failed to get the IProc Interface>
commnd.CommandText = "group=ADMIN;object=ProcParams;name=Addition"; Could not find object <ProcParams>
X2Provider Error <Object not found>
commnd.CommandText = "group=ADMIN;object=AdditionParams"; Could not find object <AdditionParams ?, ?, ?> X2Provider Error <Object not found>
commnd.CommandText = "group=ADMIN;name=Addition"; Could not find object <> X2Provider Error <Object not found>
commnd.CommandText = "group=ADMIN;proc=Addition"; X2Provider Error <Internal Error:Failed to get the IProc Interface>
Do you have any idea what I could do to get "proc=Addition" to take?
Thanks so much!
John
I am trying to be helpful, but I don't want to waste your time either, as I really don't see any obvious solution.
Honestly, if certain calls are giving you errors, then my conclusion is that the calls which do not give errors are syntactically correct. You are connecting, so that is not the issue, and when the syntax is incorrect, you get an exception, including "object not found" errors.
Just to be clear on all the tests:
- Set your Command object to CommandType.StoredProcedure and try the "commnd.CommandText = "group=ADMIN;object=Procs;name=Addition";"
- Set your Command object to CommandType.Text and try "commnd.CommandText = "group=ADMIN;object=Object;proc=Addition";"
One last suggestion: can you add a C# version of his "Illustration purposes loop". He calls cmd.Parameters.Refresh, which queries the database for the parameter types and names. You can then print the names and types to the Console or such. You would do this without adding the parameters yourself. It is a debugging procedure. Make sure they are the types you are expecting and the names you are using!
If all else fails, even if you don't have access to VB6, I believe you could write a classic ASP web page and make use of the old ADO libraries, to see if in fact you get a return value from your test environment using the old code. It would look very similar to his VB6 code.
This is not a waste of time for me. I am learning a ton about C# and ADO.Net
However I don't want to waste your time.
I did some foreach loops to gather parameter properties and during debugging the collection had no members so I'm not reaching the proc id on't believe.
I tried all execute methods ExecuteNonQuery, ExecuteScalar and ExecuteDataReader and eliminated the possiblity of the Execute method being the culprit in the failure to get IProc Interface.
I think I need to move on so don't bother responding unless you just have to tell me a new idea!
Thanks for all your help.
Well, kudos to you for sticking in there and really trying. I feel frustrated too,that you couldn't solve it. But maybe if you drop it for a few weeks you may come across something else that sheds some light on what is missing here.
The cool part is that when anyone in the entire world does a Google on "ADPProv.ADPProv.1", they will find your post here. You're famous!
In any case, I hope eventually you get the breakthrough you need so that you can work with the language and ADO libraries of your choice.
Just wanted to post this because I gave up on C# and ADO.Net with this provider so I went at getting VS2008 to compile the VB6 code listed above.
I attached a screenshot of the references I had to add and the namespace I imported to make the project work. I also had to delete some error handling code with DoEvents() etc
I really wanted to use C# ADO.Net but I don't think the provider can handle it.
Oh well at least I got it to work!
Here's the code I ended up with:
I couldn't attach a jpg file. It kept telling me it was too big even at 8 kb!?!
I imported the namespace Microsoft.VisualBasic as you can see in the code.
I added these references in addition to the usual System ones used in Windows forms development including System.Data.
Reference Name Type Version
adodb .Net 7.0.3300.0
dao .Net 10.0.4504.0
Microsoft.VisualBasic.Compatibility .Net 8.0.0.0
Microsoft.VisualBasic.Compatibility.Data .Net 8.0.0.0
Thanks for all the help,
JD
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: udo polder |
last post by:
hello all
i am having some problems calling a stored procedure on MSSQL2000 from VC7.
i have build up an OLEDB-Consumer (for stored Procs) via vizzard and
modifyed it a little, to bring in the...
|
by: Error while executing SP |
last post by:
Hi,
I am getting an error while executing a sp from Oracle database. Can you let me know what could be the problem?
here is the code
using(System.Data.OleDb.OleDbConnection cn = new...
|
by: gigi |
last post by:
I have a strange problem with an OleDB call to a stored procedure that
returns a rowset.
Only the first time I execute the query, after I restart SqlServer, my
program crashes because
the rowset...
|
by: Jeff Wang |
last post by:
Hi all,
Can someone help me out? I've been struggling with this for almost a
week and still have no clue what's wrong.
Basically I want to write a DB2 stored procedure for OS/390 in REXX.
In...
|
by: Wojciech Wendrychowicz |
last post by:
Hello to All,
I'm trying to retrieve records from AS/400 in an VBA application.
So, I've made an RPG program, then a stored procedure wchich calls that RPG
program, and finally some VBA code to...
| |
by: Dino L. |
last post by:
How can I run stored procedure (MSSQL) ?
|
by: Siv |
last post by:
Hi,
I have a stored procedure that I want to execute and then wait in a loop
showing a timer whilst it completes and then carry on once I get
notification that it has completed. The main reason...
|
by: Tom |
last post by:
Looking for some help with stored procedure call issues. Conceptually, I
need to pass a data structure as the sole parameter to the Oracle stored
procedure. Sounds simple enough....but how?
...
|
by: amgupta8 |
last post by:
Note: This problem occurred when I updated the JDK from 1.3.1 to 1.4.1 or 1.4.2.
Nothing else was changed in the code, other than updating the JDK on the database server (dbm cfg parm jdk_path) and...
|
by: jamesclose |
last post by:
My problem is this (apologies if this is a little long ... hang in there):
I can define a function in VB.NET with optional parameters that wraps a SQL procedure:
Sub Test(Optional ByVal Arg1...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |