Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ODBC connection my first attempt
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Network:
Windows Server 2008 R2
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01639227
Message ID:
01639231
Views:
101
>>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.

When I first did it, I used the 2nd way you mentioned (DSN) - but rather than using passthrough I used remote views. For me this was easy because I had been using local views for quite a while before this.

Once you get the hang of it, you'll never want to use .dbf's again :)
ICQ 10556 (ya), 254117
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform