Showing posts with label foxpro. Show all posts
Showing posts with label foxpro. Show all posts

Thursday, July 3, 2008

Division by Cucumber?

Today I let loose my latest thingy, which reads some logs and parses them into a FoxPro table. See my post on it here.

It was working fine while in the sandbox but screamed hell when I set it loose in the wild. It threw a 'DivideByZeroException' all the time. After a while of debugging and crawling through my code I ended up here:
  1. System.Data.OleDb.OleDbCommand Com = new System.Data.OleDb.OleDbCommand(Instrucions[i]);
  2. Com.Connection = conn;
  3. Com.ExecuteNonQuery();
Line 3 threw the exception... but why? The instruction looked like 'insert into tablename (Col1, Col2, Col3) values ('One','Two','Three other things added here')'.
Thing was that the first round with another table went fine and that SQLstatement was a lot more complicated! So... what gives?

Took me about 2 hours of fiddling, cursing and sniffing through my code I found out the cause:
'Col3' is a FoxPro Memofield... sheesh.. which creates the need for the corresponding 'tablename.FPT' in the directory where the free tables reside. After that it worked like a charm.

So... all the crap in the web about some complicated parameteradding and such is safely discarded. The only thing is that you should chop your strings that should go into the memofield into 255 charater pieces as FoxPro works with stringlaterals that hold 255 chars max :)

Hope I could push you a step further to enlightenment :)

Tuesday, July 1, 2008

Dinner's ready, I already filled the FoxPro table!

Fighting my way through C# and its various... uh... specialities I ran head on into the problem of filling a FoxPro table. Being the smart guy I ventured to the Internet and looked for a solution.

Problem:
A directory of free tables to which I want to connect via C#.

Internet solution:
  1. Download the Visual FoxPro 9.0 OLEDB driver
  2. Install (duh :) )
  3. 'using System.Data;'
  4. Jump around to Connectionstrings.com and get the correct connectionstring
  5. Start filling that table!
Well so far so good, this is what I got (edited so it fits this layout):

  1. string vfpConnectionString="Provider=vfpoledb.1;Data Source=C:\\temp\\fptest\\;Collating Sequence=general;";

  2. conn = new System.Data.OleDb.OleDbConnection(vfpConnectionString);
  3. conn.Open();
  4. System.Data.OleDb.OleDbCommand Com = new System.Data.OleDb.OleDbCommand("[SQL goes here]);

  5. Com.Connection = conn
  6. Com.ExecuteNonQuery();
  7. conn.Close();
Now then... away with testing and... behold... nothing. WTF? The driver is not registered? Okies... go intall again... poo... no luck... what gives? After another round of doing the same... the same.. hehehe... not registered [instert heavy cursing on MS, SQL, FoxPro and Windows].
'Oh crap on FoxPro... I go to bed'

[Birds chirping] Next day at work:
Installed the same sequence again... WOW! Works! What gives?

Now then... education starting, sit down, be quiet and read up:

If you have, like me, a Vista64 Ultimate at home and a Vista32 Business at work... you get the drift? Yes! No 64bit with the FoxPro drivers! [claps] Very good! Get a Snickersbar and be proud.

Solution? Easy:
  1. Create your FoxPro-Accessing-Application-to-be
  2. Go to 'Build' -> 'Configuration Manager...'
  3. Find your Project (should be easy if you only have one in there)
  4. Click on the 'Platform' DropDown and choose ''
  5. 'New Platform' and choose 'x86' and '>'
  6. 'Ok' everything, make sure 'x86' is set as target CPU
  7. Build and frolic
Now you can use the FoxProtables as if they were 'normal' tables in a database. Meaning:
'Select * from ste_q3 where current=3.35'

Oh and by the way I recommend DBFManager which is quite a powerful (and inexpensive) way to sniff around in those tables without having FoxPro installed.

I hope I saved at least a bit of someone's troubles with this :)

Oh.. and I just read up on static variables in functions and C#... I go on with that in the next post, because it is a separate thing to rant about :)