Hello to you X# community

We encourage new members to introduce themselves here. Get to know one another and share your interests.
Post Reply
Posts: 2
Joined: Mon Nov 28, 2022 5:16 pm

Hello to you X# community

Post by StacyViolett »

Hello all,

Robert and Fabrice,

My name is Stacy Violett with Black Mountain Software. We are very excited to explore possibilities of using X# for a supported method of data access to foxpro data. I spoke with you and Fabrice at a Q&A session following your class at Visual Foxfest Session on Thursday, October 13th.
We are researching technology solutions for building a client facing restful API which will access foxpro free tables or vfp tables in a dbc.

To get started, we have some initial questions about how we might go about using X# for accomplishing our goal.
Our team worked through your wonderful example and got a working demo using Visual Studio 2022 to access local data.
- Hulst_FromFoxToNet.pdf - page 19

There are 2 initial questions we have.

**Item 1 ** - how can we build a reference to define a connection string to our remote data servers on the fly
- use an api or database we control which stores a data location of our choice based on parameters

example result - dbf://someserver.bmshelp.com:3099/D:data/folder/cetest/UB

This would be similar to our discussion about how Advantage Database Server can access data remotely.
We would prefer the access uses native X# data methods instead of Microsoft ODBC or OLEDB as we want the process of data access to be supported in X#. We need to be able to access a remote database of either free tables or tables in a Database Container

** Item 2 ** - what method and syntax is required to query remote data from Item 1 with fox type commands or sql commands and return the values in JSON

I have added notes into your document example from page 19 to try and describe our needs below:

Assume we have the following code in a project of type “Class Library”

Code: Select all

Define Class Customer As Custom
 Procedure FullName_Access As String
 Return This.FirstName+" "+This.LastName
End Define
This will create a normal .Net class that we can use from a C# project like this:
var customer = new Customer();
customer.LastName = "Doe";
customer.FirstName = "John";
As far as the C# app is concerned this is no different then a class developed with C#. When
you run this in the debugger you can also step through the code from C# to X# and back
If you want to access data from a DBF file then this is also relatively easy. Add a new
method to the Customer class

Code: Select all

Static Function GetNames As String
 Local sb As StringBuilder
 Field FirstName, LastName

** Item 1 ** get our connection string
** Set Default To c:VFF2022TestData **
** define our remote data connection string **    dbf://someserver.bmshelp.com:3099/D:asp/netdrive/cetest/UB

** Item 2 ** syntax/example for the connection itself
What syntax and methods are used to make the remote connection?

 sb = StringBuilder{}
 Use Customer
 Go Top
 Sb.AppendLine(Trim(FirstName)+" "+Trim(LastName))
 End scan

The “Static” prefix tells the compiler that to use this method there is no need to instantiate
an object first. The Field command tells the compiler that FirstName and Lastname are
fields, so there is no ambiguity in the code.
To use this from C# you can call the method like this:
Again, you can debug from C# into the X# code, see the customer table being opened and

Thanks much for your help!
Stacy Violett
User avatar
Posts: 3815
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Hello to you X# community

Post by robert »

Welcome on the forum.
Since your question is about the paper that I wrote for Virtual Fox, I guess that I am the one that should answer it :) .

1) The page in the documentation refers to the connection string for SqlStringConnect(). At this moment this connection string needs to be either a valid ODBC connection string, OleDb connection string or a SQLClient connection string, depending on the provider that you have chosen.
All three connection types use a Ado.Net data provider in the background.

To access a remote database of free tables or a Database container then we would need an Ado.Net data provider for DBF files. At this moment the only solution there is the Advantage .NET Data Provider.
We are looking into creating our own replacement for Advantage Database Server, since SAP is no longer actively developing ADS. I cannot give a time frame for that.

2) If you use a Ado.Net data provider then it would be the normal SqlStringConnect() followed by SqlExec() and working your way through a cursor.

If there is a demand for this in the FoxPro community we can already add a XSharp.Data.ADSFactory class that uses the Advantage .NET Data Provider.
You could then use code like this

Code: Select all

SqlSetFactory(XSharp.Data.ADSFactory {})
SqlStringConnect("Data Source=n:MyDatamyData.ADD; ServerType=Remote;")
And then fetch data with SqlExec() and process it.

You will not be able to use FoxPro Database containers with Advantage. You need to migrate the data to an advantage Data Dictionary (ADD)

Returning the values as JSON should be easy. Usually you create a collection of objects first and then use the normal .Net components, like NewtonSofts JSon component to save the objects into a json string.

I hope that this answers your questions?

XSharp Development Team
The Netherlands
Posts: 2
Joined: Mon Nov 28, 2022 5:16 pm

Hello to you X# community

Post by StacyViolett »

Robert, thanks for your quick reply.

We may put together some more questions on the VFP forum for you.
Post Reply