Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ODBC with VFP , any tutorial?

Status
Not open for further replies.

Takusaan

Programmer
Sep 20, 2000
29
0
0
US
I need to access remote data but never used ODBC before. can anyone give me directives or suggestion?
 
Actually it's real easy... after you've done it a couple of times. The first time you tend to get lost.

Anyway, you first create an ODBC connection in windows to your database. This is done through Start/Settings/Control Panel. In Win 9x there's a separate ODBC setup icon. In Win 2000 you have to open the Administrative Tools folder in the Control Panel to find it "Data Sources(ODBC)"

Use either the first or second tab (depending on whether there are other uses who need your data source or not) and click 'add. ' This lets you select what sort of database you're connecting to. Then you have to fill in the data in the next screen and test it.

After that, you can create a remote view in VFP using that data source. When you do this you can either create connections first and then use them to create the remote view, or click the radio button for data sources and select the Windows data source you created.

Let us know how far you get trying this.
 
lcDSNless= "DRIVER=SQL Server;SERVER=DATA_SERVER;Trusted_Connection=Yes;DATABASE=FoxproApps;APP=MyFoxPro"

lnDSNless = SqlStringConnect(lcDSNless)


the above code will allow you to connect to an SQL server without an ODBC DSN entry
here is an explanation of what is going on

DRIVER:
this Driver entry allows you to define the specfic ODBC or OLEDB driver to use in order to connect to a database.


Server:
this is the Server destantion the Netbois, IP address, or DNS name.


Trusted_Connection:
this feature allows you to grab the current log on user to the computer. No extra code is needed.
This only works to my knowlegde with SQL server which can intergate into NT securtiy.

I use this feature allot. It works on 98 NT4.0 and W2K i know this because that is what we run.


If you can not use trusted_Connection
Simply replace with uid= and Pwd= this assums that the user has access to the Database and Server.


DATABASE:
is the remote database name located on the SQL server


App:
this is the name of the application as it will appear on the SQL server


lnDSNless:
is the connection handle which if everything worked correctly came back with a Possitive integer, anything less than 0 it failed. so do a test,el like so

IF lnDSNless < 0
wait window &quot;I failed to connect to the DATABASE oh SHIT&quot; timeout 5
else
my_code_stuff()
endif




If you don't like useing dsnless connection. simply use a predefine ODBC dsn.

then call it like so

lnConnect = SQLConnect(&quot;AN_ODBC_DSN&quot;)

If lnConnect < 0
wait window &quot;I failed to connect to the DATABASE oh SHIT&quot; timeout 5
else
my_code_stuff()
endif


This above code is example on how to connect to a remote databse via SQL Passthrough

it is not as easy to code but far faster and can run the Database native laugauge

The following command are helpful in SQL Passthrough and are required

SqlCancle()
SqlColums()
SQLCommit
SQLConnect()
SqlDisconnect()
SQLEXEC()
SQLGETPROP()
SQLMORERESULTS()
SQLPreapre()
SqlRollBack()
SqlSetPROP()
SqlStringConnect()
SqlTables()

All these command are avaible in 5.0 6.0 and 7.0

all these commands work best on SQL SERVER.

If you cannot figure out how to use SQL PassThrough go with remote views.

I personal hate remote views becasue there so dam slow, but are easy to use. Also 7.0 ships with an SQL Passthrough class libary

Hope this is helps

my e-mail is justin@emproshunts.com

I can send you some code examples
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top