Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ODBC connection my first attempt
Message
De
08/08/2016 17:29:53
 
 
À
08/08/2016 14:45:04
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Network:
Windows Server 2008 R2
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01639227
Message ID:
01639230
Vues:
100
>My parent company is requiring that I do some database work and they have given me VPN access through the Dell SonicWall / Nextextender application.
>
>I need to access their SQL database with my VFP and use the data accordingly for our uses here.
>
>They have given me the following, I just need a boost in the right direction as I am used to dealing with just the native foxpro data...
>
>SQL Server: ECD-SVR-SQL
>
>
>Database: ECNC Interface
>
>View: ECNC_CO_View (Read Access)
>
>Tables: ECNC_invoice_info (Read/Write Access)
> ECNC_shipping.info (Read/Write Access)

Steve

There are several ways of connecting to a SQL Server Database from VFP

I've used two.

The one I've come to prefer is to connect progammatically use the vfp sqlserver driver

Here's some code I used recently
convdata is a dbf I use for connection information
gc_sqlserver = ALLTRIM(convdata->sqlserver)
gc_sqluser = ALLTRIM(convdata->sqluser)
gc_sqlpassword = ALLTRIM(convdata->sqlpw)
gc_database = ALLTRIM(convdata->sqldb)



*-- Connect to SQL Server
SET MESSAGE TO "connecting"
lcConnString ="Driver=SQL Server;Server=" + gc_sqlserver + ";Database=" + gc_database
lcConnstring = lcConnstring + ";UID =" + gc_sqluser + ";PWD =" + gc_sqlpassword 

gnsqlHandle = SQLStringConnect(lcConnString)
if gnsqlHandle < 1
**   you have a connection problem
endif
The other way is to create a DSN on your desktop.
Google DSN and SQL Server to find out how to do that.
Once you get a DSN, you can connect to it this way:
 gnConnHandle = SQLCONNECT(myDSNname, myuserid,mypassword)

   if gnConnlHandle < 1
**   you have a connection problem
endif
Once you have the handle, you can use it to access tables.
There are lots of ways to do that, but I prefer SQL Passthrough.
This code puts all the data in SQL Server table mytable into a VFP cursor called curmytable:
= SQLPREPARE(gnConnHandle, "SELECT * FROM mytable", ;
  "curmytable")
= SQLEXEC(gnConnHandle)
You might want to try a connection and a simple query.
After you get them working you can do just about anything you want.
VFP Help has lots of good examples of SQL Passthrough.
That's where I began.
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform