TechMate


Hi

I want to run a stored procedure in user selected database which basically creates two new tables to be persisted in the same database. I am able to call this stored procedure but I keep getting the same error "One or more errors occurred during processing of command." There are no details of what the error is specifically about. I am able to run the same stored procedure using Microsoft Visual FoxPro 9.0 software.

My Connection string is "provider='VFPOLEDB.1';data source='strPathName.dbc';password='';user id='';Mode=ReadWrite". Any ideas or suggestions are appreciated.

Try
If VFP7Connection Is Nothing Then VFP7Connection = New OleDbConnection(VFP7ConnectionDefinition)
If VFP7Connection.State = ConnectionState.Closed Then VFP7Connection.Open()
If VFP7SelectCommand Is Nothing Then VFP7SelectCommand = New OleDbCommand

VFP7SelectCommand = VFP7Connection.CreateCommand()
VFP7SelectCommand.CommandText = "DO PROCESS_LOCATION_VIEW_TABLES"
VFP7SelectCommand.ExecuteNonQuery()
Catch ex As Exception
Throw ex
Finally
If VFP7Connection.State = ConnectionState.Open Then VFP7Connection.Close()
End Try



Re: Errors running FoxPro Stored procedures in .NET windows app

CetinBasoz


There is no stored procedure call like:

"DO process_location_view_tables"

DO is a VFP keyword an should never be used in place of a stored procedure name. If it was really a stored procedure name, then instead of passing the parameter like that, use OleDbParameter. ie:

string lcConStr = @"Provider = VFPOLEDB;Data Source=c:\my Path\testdata.dbc;";
OleDbConnection loConnection = new OleDbConnection(lcConStr);
loConnection.Open();

OleDbCommand loCommand = new OleDbCommand();
loCommand.Connection = loConnection;
loCommand.CommandText="GetCustomerMax"; // sample stored procedure returning scalar value
OleDbParameter parm = new OleDbParameter("","ALFKI");

loCommand.Parameters.Add(parm);
loCommand.CommandType=CommandType.StoredProcedure;
try
{
decimal rv = (decimal)loCommand.ExecuteScalar();
Console.WriteLine(rv);
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
loConnection.Close();
}

As I see you're using VFP7 naming your objects and stored procedure as your SelectCommand (probably jus a misnomer). If your intend is to return a resultset then you need VFP9 and later. VFP7 stored procedures can only return a scalar value. Stored procedures do return a value and you should use ExecuteScalar() or ExecuteQuery() depending on what you expect. ie: A VFP9 stored procedure could return a resultset:

string strConn = @"Provider=VFPOLEDB;Data source=c:\my Path\myDatabase.dbc;";

OleDbConnection cn = new OleDbConnection(strConn);

OleDbCommand cmd = new OleDbCommand();
cmd.Connection = cn;
cmd.CommandText = "myStoredProcedure";
cmd.CommandType = CommandType.StoredProcedure;
OleDbParameter userID = cmd.Parameters.Add("userID",2);

OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);

foreach (DataRow row in ds.Tables[0].Rows)
{
Console.WriteLine((string)row["UserName"]);
}
}

PS: It's never wise to create tables from a stored procedure over and over. Maybe all you need is to return a resultset or a nested XML etc.

I do not think you really ran that as a stored procedure from within VFP9. Probably actual stored procedure name was part after "do" with no parameters. Keep in mind not all commands and functions are supported through OLEDB calls (check supported/unsupported in VFP help).





Re: Errors running FoxPro Stored procedures in .NET windows app

TechMate

Thanks for some insight on what can or cannot be done with VFP7 drivers. This stored procedure is not executed everytime. It is used by an site administrator once a month to update new data for generating reports (after importing them from flat files using an unknown propreitery module).

I have Microsoft Visual Foxpro 9.0 Software installed on Server 2003 machine. The windows app is specifically referencing vfpoledb.dll (version 7.0.0.9465) for attempting to execute the stored procedure. I used the FoxPro software to create the stored procedure but I am calling this procedure from VFP7. Is this even possible or am I wasting my time here

I tried your code sample with OleDbParameter & ExecuteScalar() and now I get this error "Unrecognized command or verb."

Your response will greatly help make a decision for this issue.






Re: Errors running FoxPro Stored procedures in .NET windows app

CetinBasoz

VFPOLEDB drivers are not for VFP7/9 specifically, it's for any foxpro version. It just gets updated as all drivers do. First download the latest driver from MS VFP site downloads and install that one.

OTOH what you can use in a stored procedure is version dependant. ie: VFP7 doesn't know what SetResultSet() function is.

I don't understand what do you mean by "I am calling this procedure from VFP7. Is this even possible...". If it weren't possible VFP wouldn't even have something called stored procedure, no Reread my previous post carefully. At this point I think that you are not calling a stored procedure but you think you do. From your OleDbCommand.CommandText there can be no such stored procedure call, in VFP, SQL server, Oracle or whatever. It is wrong, see OleDbCommand help on MSDN. Second, I repeat it's a little suspicious you do it on SelectCommand and yet say it's creating for tables (and of course I repeat again, it's not wise to create tables over and over again in a dbc be it once a month or once a year - if that is for reporting, use a resultset or a view etc, if none helps use free tables. I am not sure your site admin understands the tables in a database. If it were SQL server or Oracle, would he still be creating tables just for reporting each month Really weird approach).

You tried my sample, so far so good but did you create the stored procedures If you did, did you debug for the offending code in your stored procedure Show your stored procedure code, so I might have an idea what you did wrong.





Re: Errors running FoxPro Stored procedures in .NET windows app

TechMate

I think you misunderstood my previous post. I am not using SelectCommand (it happens to be part of variable name used in the original code snippet, VFP7SelectCommand). Correct me if I am wrong.

I am attaching the stored procedure in the sample VFP database below (created using VF9.0 Software): Please note there are 3 procedures and I am trying to execute PROCESS_LOCATION_VIEW_TABLES from the windows application.




Re: Errors running FoxPro Stored procedures in .NET windows app

CetinBasoz

I warned you to check documentation:)

Anyway I played with your SP code a bit:

PROCEDURE PROCESS_LOCATION_VIEW_TABLES(tcDataPath)
 CREATE cursor __Temp (loc C(60), bill_date C(8), Total N(11,2))
 INSERT INTO __Temp (loc, bill_date, total) ;
 SELECT order_id as loc, DTOC(order_date,1) as bill_date, order_net as total ;
 FROM orders WHERE cust_id like "A%"
 INSERT INTO __Temp (loc, bill_date, total) ;
 SELECT order_id as loc, DTOC(order_date,1) as bill_date, order_net as total ;
 FROM orders WHERE cust_id like "B%"
 INSERT INTO __Temp (loc, bill_date, total) ;
 SELECT order_id as loc, DTOC(order_date,1) as bill_date, order_net as total ;
 FROM orders WHERE cust_id like "C%"
 INSERT INTO __Temp (loc, bill_date, total) ;
 SELECT order_id as loc, DTOC(order_date,1) as bill_date, order_net as total ;
 FROM orders WHERE cust_id like "D%"

 CREATE table (ADDBS(m.tcDataPath)+"CollectDataFor201") FREE ;
 (loc C(60), bill_date C(6), Total N(11,2))
 INSERT INTO CollectDataFor201 (loc, bill_date, total) ;
  SELECT loc, bill_date, SUM(Total) FROM __Temp GROUP BY loc, bill_date
 USE IN '__Temp'
 USE IN "CollectDataFor201"
ENDPROC

The selects in insert should be replaced with yours. They are there to show it works with this call (assuming testdata.dbc is in c:\temp\data). It's unnecessary to create __temp as a table. Also result table is better when it is a free table. No need to make that part of database:

using System;
using System.Data;
using System.Data.OleDb;

class SPsample
{
 static void Main()
 { 
   string strConn = @"Provider=VFPOLEDB;Data source=c:\temp\data\testdata.dbc;";

   OleDbConnection cn = new OleDbConnection(strConn);

   OleDbCommand cmd = new OleDbCommand();
   cn.Open();
   cmd.Connection = cn;
   cmd.CommandText = "PROCESS_LOCATION_VIEW_TABLES";
   cmd.CommandType = CommandType.StoredProcedure;
   OleDbParameter myPath = cmd.Parameters.Add("myPath", @"c:\temp");
   bool result = (bool)cmd.ExecuteScalar();
   cn.Close();
   Console.WriteLine(result);
 }
}




Re: Errors running FoxPro Stored procedures in .NET windows app

TechMate

Thank you very much. I figured out the issue. It was not the stored procedure but driver problem. I though i was referencing to VFPOLEDB 9.0 version but I realized I had a DLL for 7.0 and it was registered in my computer. After I unregistered 7.0 and re-registered 9.0, the stored procedure worked fine.

Only 1 issue though ; I get "Feature not available" error when I try to execute DROP TABLE tablename command in the stored procedure. I looked at supported and unsupported commands for OLE DB in the documentation and confirmed DROP TABLE is in fact supported. Any ideas

Also if I create a CURSOR like in your previous example, how do I loop through the data in that cursor Will this sample below work

CREATE cursor __Temp (loc C(60), bill_date C(8), Total N(11,2))
INSERT INTO __Temp (loc, bill_date, total) SELECT loc, bill_date, total FROM hdnf033_ABN
USE __Temp

DO WHILE .T.
IF EOF()
EXIT
ENDIF
* ------ get data from the row and process commands
SKIP
ENDDO

Thank you very much for your help





Re: Errors running FoxPro Stored procedures in .NET windows app

CetinBasoz

CREATE cursor __Temp (loc C(60), bill_date C(8), Total N(11,2))
INSERT INTO __Temp (loc, bill_date, total) SELECT loc, bill_date, total FROM hdnf033_ABN
scan
 * ------ get data from the row and process commands
ENDscan

or:


SELECT loc, bill_date, total FROM hdnf033_ABN INTO cursor __Temp
scan
 * ------ get data from the row and process commands
ENDscan

From one of earlier posts:

" VFPOLEDB drivers are not for VFP7/9 specifically, it's for any foxpro version. It just gets updated as all drivers do. First download the latest driver from MS VFP site downloads and install that one.

OTOH what you can use in a stored procedure is version dependant. ie: VFP7 doesn't know what SetResultSet() function is."

I didn't think that you didn't read.





Re: Errors running FoxPro Stored procedures in .NET windows app

TechMate

I have the latest version of Foxpro OLEDB. I downloaded it again and ran the setup and I can confirm it prompts "Modify, Repair, Remove" options in the setup.

Any ideas on "DROP TABLE tablename" statement throws "Feature not available"





Re: Errors running FoxPro Stored procedures in .NET windows app

CetinBasoz

No I don't have any idea. As I showed you you don't need to drop a table either.



Re: Errors running FoxPro Stored procedures in .NET windows app

TechMate

Thanks for all your help with these issues.