Page 1 of 2

Where i can find "FiveODBC Documentation"

PostPosted: Wed Aug 22, 2018 5:17 pm
by max
I'd like to know more about FiveODBC classes. Opening the file help file of FiveWin Classes i find the class TdbOdbc, TOdbc, ecc. but the manual suggest "Please consult FiveODBC Documentation". Where i can find it? I search online into "Fivetech Software Wiki" too, but i didn't find Five ODBC Documentation.
Thank you!
Max

Re: Where i can find "FiveODBC Documentation"

PostPosted: Thu Aug 23, 2018 2:39 pm
by Antonio Linares
Max,

FWH current ADO support is the way to go:

viewtopic.php?f=3&t=32657

Re: Where i can find "FiveODBC Documentation"

PostPosted: Fri Aug 24, 2018 10:35 am
by max
Antonio,
two questions:
1) i'm using FWH version 15.06. I have to upgrade my version for ADO support in FWH ?
2) Superflous i think, but just to be sure: is it ok and recommended with databases "SQL Server" too?

Thank you
Max

Re: Where i can find "FiveODBC Documentation"

PostPosted: Fri Aug 24, 2018 10:57 am
by Antonio Linares
Max,

1) Yes

2) Yes

Re: Where i can find "FiveODBC Documentation"

PostPosted: Fri Aug 24, 2018 12:05 pm
by max
Ok Antonio: upgrade order done.

Bye

Re: Where i can find "FiveODBC Documentation"

PostPosted: Fri Aug 24, 2018 2:06 pm
by Antonio Linares
Max,

Many thanks

Please review fwh\samples\mariainv.prg

There you have an ADO full working example :-)

Re: Where i can find "FiveODBC Documentation"

PostPosted: Sat Aug 25, 2018 6:55 pm
by max
The example inside mariainv.prg seems to work only with "MySQL Server", isn't it? Instead, i need to connect to an SQL SERVER database.
I try compiling the form of mariainv "own server" with cHost,cuser,cpassword,cdb variables but alwais receive an error like this:
"2003 Can't connect to MySQL server on 'NAMEPC' (10061)" , where NAMEPC=name of my pc that run SQL SERVER 2017 EXPRESS EDITION .
Maybe FWCONNECT works only with Mysql and not with Sql Server?
Where am i wrong?

Re: Where i can find "FiveODBC Documentation"

PostPosted: Sat Aug 25, 2018 11:36 pm
by admsoporte
max wrote:The example inside mariainv.prg seems to work only with "MySQL Server", isn't it? Instead, i need to connect to an SQL SERVER database.
I try compiling the form of mariainv "own server" with cHost,cuser,cpassword,cdb variables but alwais receive an error like this:
"2003 Can't connect to MySQL server on 'NAMEPC' (10061)" , where NAMEPC=name of my pc that run SQL SERVER 2017 EXPRESS EDITION .
Maybe FWCONNECT works only with Mysql and not with Sql Server?
Where am i wrong?
Me parece que el soporte a MySQL nativo es a partir de FWH1612

Enviado desde mi FIG-LX3 mediante Tapatalk

Re: Where i can find "FiveODBC Documentation"

PostPosted: Sun Aug 26, 2018 10:16 am
by max
Jose,
i'm using latest FWH release: 1805. And i need native support for SQL SERVER, not for "MySQL".
I access to my database SQL via ODBC regularly, but today the best way is to access via ADO.
But how? I need just an example of native connection to SQL SERVER database, avoiding to configure ODBC.
In \fwh\samples i find only examples for db MySQL via FWCONNECT.

Thank you.

Max

Re: Where i can find "FiveODBC Documentation"

PostPosted: Sun Aug 26, 2018 11:00 am
by Enrico Maria Giordano
You have to use a connection string like this:

Code: Select all  Expand view
Provider=sqloledb;Data Source=<ipaddress>;Initial Catalog=<databasename>;User Id=<userid>;Password=<password>


EMG

Re: Where i can find "FiveODBC Documentation"

PostPosted: Sun Aug 26, 2018 11:03 am
by Enrico Maria Giordano
A code sample (not working):

Code: Select all  Expand view
// ADO definitions

#define adOpenForwardOnly 0
#define adOpenKeyset      1
#define adOpenDynamic     2
#define adOpenStatic      3

#define adLockReadOnly        1
#define adLockPessimistic     2
#define adLockOptimistic      3
#define adLockBatchOptimistic 4

#define adUseNone   1
#define adUseServer 2
#define adUseClient 3


oRs = CREATEOBJECT( "ADODB.Recordset" )

oRs:CursorLocation = adUseClient

oRs:Open( "SELECT * FROM YourTable", cConnectionString, adOpenForwardOnly, adLockReadOnly )

? oRs:Fields( "MyField" ):Value

oRs:Close()


EMG

Re: Where i can find "FiveODBC Documentation"

PostPosted: Sun Aug 26, 2018 10:18 pm
by nageswaragunupudi
Connecting to Microsoft SQL server using FWH simplified ADO functions.


FWH provides a single line function FW_OpenAdoConnection( <parame,,,> ) to connect to any server, MSSQL, ORACLE, MYSQL,MSACCESS, etc.

In case of MSSQL, the server can be configured to login using Windows Authentication (also called Integrated Security) and/or using Username and password. Later is preferable.

The following sample (ado1.prg) demonstrates connecting to MSSQL server using this function and then view all the databases available on the server and also to create a new database "FWHADO" for further tests.

ado1.prg:
Code: Select all  Expand view
#include "fivewin.ch"
#include "adodef.ch"

static oCn

//----------------------------------------------------------------------------//

function Main()

   local cServer     := "SQLEXPRESS"  // your server address
   local cInitialDB  := ""            // for now we keep it empty
   local cUser       := "SA"
   local cPassword   := "password"  // your password
   local aCredentials, aDB

   // If connecting by Windows authentication (Integrated Security)
   aCredentials   := { "MSSQL", cServer, cInitialDB }
   // If connecting by Username and Password
   aCredentials   := { "MSSQL", cServer, cInitialDB, cUser, cPassword }

   ? "Trying to connect"
   oCn            := FW_OpenAdoConnection( aCredentials, .T. )
   if oCn == nil
      ? "Failed to connect"
      return nil
   endif

   ? "Successfully connected to server"

   // Let us view list of databases existing on the server
   aDB      := FW_AdoCatalogs( oCn )

   XBROWSER aDB TITLE "List of databases"

   if AScan( aDB, { |c| Upper( c ) == "FWHADO" } ) == 0
      // Database FWHADO does not exist
      // We crete it now

      oCn:Execute( "CREATE DATABASE FWHADO" )
      ? "Created Database FWHADO"
   endif

   oCn:Close()

return nil

//----------------------------------------------------------------------------//
 


If the above sample successfully works, then we can go to the second example (ado2.prg).
This sample connects to the server with initial database FWHADO, imports one DBF from the \fwh\samples folder and opens the newly imported table for edit. We can edit, append new records as we like.

ado2.prg
Code: Select all  Expand view
#include "fivewin.ch"
#include "adodef.ch"

REQUEST DBFCDX

static oCn

//----------------------------------------------------------------------------//

function Main()

   local cServer     := "SQLEXPRESS"  // your server address
   local cInitialDB  := "FWHADO"
   local cUser       := "SA"
   local cPassword   := "password"  // your password
   local aCredentials, oRs

   // If connecting by Windows authentication (Integrated Security)
   aCredentials   := { "MSSQL", cServer, cInitialDB }
   // If connecting by Username and Password
   aCredentials   := { "MSSQL", cServer, cInitialDB, cUser, cPassword }

   ? "Trying to connect"
   oCn            := FW_OpenAdoConnection( aCredentials, .T. )
   if oCn == nil
      ? "Failed to connect"
      return nil
   endif

   ? "Successfully connected to server"
   ? "Importing DBF"

   FW_AdoImportFromDBF( oCn, "c:\fwh\samples\states.dbf" ) // give your dbf with full path

   // Open table
   oRs   := FW_OpenRecordSet( oCn, "SELECT * FROM STATES" )
   if oRs == nil
      ? "Failed to open table"
   else
      XBROWSER oRs FASTEDIT AUTOSORT
      oRs:Close()
   endif

   oCn:Close()

return nil

//----------------------------------------------------------------------------//
 


We can view all the ADO functions in \fwh\source\function\adofuncs.prg

To learn all about ADO
https://www.w3schools.com/asp/ado_intro.asp

Re: Where i can find "FiveODBC Documentation"

PostPosted: Wed Jan 09, 2019 9:10 pm
by max
I'm testing ADO functions for accessing to a database of SQL SERVER. Ado1.prg and ado2.prg run ok! Now i need to export a table to a dbf, so i'm trying to use FW_ADOExportToDbf function.

At Runtime, i receive msgbox error "DBFCDX needs to be linked" , but i already have DBFCDX.LIB linked in my exe ! Where i'm wrong??

Thank you.

Re: Where i can find "FiveODBC Documentation"

PostPosted: Fri Jan 11, 2019 6:02 pm
by max
Sorry, I solved by adding REQUEST DBFCDX that was missing.

Re: Where i can find "FiveODBC Documentation"

PostPosted: Wed Apr 24, 2019 1:48 pm
by max
Rao,
ado functions are great for accessing SQL, thank you! Import from dbf, export and browse are ok and it run very fast.
Now I need two examples, if possible:
1) how can i add records to an existing table of a database SQL in "batch" mode (not interactively with browse and similar)?
2) how can i replace a content of a field in a specific record of an existing table (like "replace fieldname with variablename" in a dbf)?

Someone have an example to post?

Thank you