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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connect to server

Status
Not open for further replies.

simco

Programmer
May 25, 2001
41
0
0
CA
I want to use Visual FoxPro as a front end for my application. I know about SQLCONNECT(), but I don't know where to write it. I want to create a lot of forms and I want to be able to select only the table in the Data Environment, not having to write a SQLCONNECT for every form. Do I make sense?

Thanks for help!
 
I tried the view and they are too slow. That's why I need the SQLCONNECT.
 
I tried the views and they are too slow. That's why I need the SQLCONNECT.
 
Simco

You can do this using the following code. Its not ideal, but it works, but I know there is a better way of defining the connection string to avoid using the DSN. When I dig it out I will post it. You will need to set up a DSN to your SQL Server and change the code posted accordingly. You have to have a database in which to store the remote connection. For the sake of this code a temp dbc is created.

Code:
*--Create a Temporary Database
local lcPath1
lcPath1=curdir()

lcDBC=sys(3)
create database &lcDbc

*--Create a Connection
LOCAL lcCommand, lcRemote, lcConnString
lcConnString = "dsn=Lisa;User ID=sa;Pwd=Lisa;Catalog=MIS"  && connection String
lcRemote = "REMOTE_01"  && name of remote connection
lcCommand='create connection ' + lcRemote + ' connstring "' + lcConnString + '"'

&lcCommand

*--Now Connect
LOCAL lnHandle
lnHandle = sqlconnect(lcRemote)

*--Execute SQL Select

LOCAL lcSql
lcSql="select * from TestTable"  && your SQL Command here

*--Fire a SqlExec
LOCAL lnSuccess
lnSuccess = SQLEXEC(lnHandle, lcSql, "cursor1")

WTrueman
...if it works dont mess with it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top