Welcome, Guest
Username: Password: Remember me
Welcome to the XSharp forum!

Tell us and our members who you are, what you like and why you became a member of this site.
We welcome all new members and hope to see you around a lot!
  • Page:
  • 1

TOPIC:

Hello to you X# community 01 Dec 2022 21:11 #24607

  • StacyViolett
  • StacyViolett's Avatar
  • Topic Author


  • Posts: 2
  • 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”
    Define Class Customer As Custom
     LastName=””
     FirstName=””
     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";
    MessageBox.Show(customer.FullName);
    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
    again.
    If you want to access data from a DBF file then this is also relatively easy. Add a new
    method to the Customer class
    Static Function GetNames As String
     Local sb As StringBuilder
     Field FirstName, LastName
    
    ** Item 1 ** get our connection string
    ** Set Default To c:\VFF2022\TestData **
    ** 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
     Scan
     Sb.AppendLine(Trim(FirstName)+" "+Trim(LastName))
     End scan
     Use


    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:
    MessageBox.Show(Customer.GetNames());
    Again, you can debug from C# into the X# code, see the customer table being opened and
    traversed.


    Thanks much for your help!
    Stacy Violett

    Please Log in or Create an account to join the conversation.

    Hello to you X# community 02 Dec 2022 12:41 #24616

    • robert
    • robert's Avatar


  • Posts: 3286
  • Stacy,
    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
    SqlSetFactory(XSharp.Data.ADSFactory {})
    SqlStringConnect("Data Source=n:\\MyData\\myData.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?

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Hello to you X# community 02 Dec 2022 16:55 #24633

    • StacyViolett
    • StacyViolett's Avatar
    • Topic Author


  • Posts: 2
  • Robert, thanks for your quick reply.

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

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1