Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Bernard Bout
  Where is Bernard Bout?
 Brisbane
 Australia
 Bernard Bout
 To: MENDEL TOLIBAS
  Where is MENDEL TOLIBAS?
 makati
 Philippines
 MENDEL TOLIBAS
 Tags
Subject: RE: sql connection
Thread ID: 78526 Message ID: 78531 # Views: 2 # Ratings: 0
Version: Visual FoxPro 7 Category: Databases, Tables and SQL Server
Date: Wednesday, October 05, 2005 6:09:31 AM         
   


> Good Day To All
> As of now we're to migrate our data to sql server , It was installed in my computer and i'm trying to connect but it's not succesful, when i using query analyzer the sql server is local and in windows authentication, What should I do?
> Thanks




Use this string

Driver={Sql Server};Server=MyServerName;Database=MyDatabaseName;Trusted_Connection=Yes;

where

MyServerName is the name you have given your server. Usually the name of your computer. If you type ?SYS(0) in the VFP command window you will get SERVERNAME#Username. That is the name you can usually use.

MyDatabaseName is the name of your database eg. Northwind

So you create a connection like:

cConnStr = [Driver={Sql Server};Server=MyServerName;Database=MyDatabaseName;Trusted_Connection=Yes;]
oConn = Sqlstringconnect(cConnstr)
If oConn<0
	Messagebox("Could not connect to the Database at this time.",16,"Error",0)
	Return
Endif


Now you can set properties of the connection like this


* set connection timeout of 20 secs
* changed to 0 since fox does not honour settings
SQLSETPROP(oConn,"IdleTimeout",0)

* set collation
SQLEXEC(oconn,"Set Language British")


and query tables like this

ddate = {22/06/2005}
nRet = SQLEXEC(oConn,[select top 10 * from client where startdate=?ddate],"RetCursor")
IF nRet < 0
	AERROR(aer)
	MESSAGEBOX(aer[2])
	RETURN .F.
ENDIF
* lets see the data
BROWSE


Hope this helps.

ENTIRE THREAD

sql connection Posted by MENDEL TOLIBAS @ 10/5/2005 3:12:57 AM
RE: sql connection Posted by Bernard Bout @ 10/5/2005 6:09:31 AM