Wiki Home

VFP Command SQL Connect

Namespace: WIN_COM_API
See Also: VFP Command SQL String Connect

SQLCONNECT([cDataSourceName, cUserID, cPassword | cConnectionName])
Returns: Numeric
cDataSourceName - Specifies the name of a data source as defined in your Odbc.ini file.
cUserID - Specifies a user identifier used to log on to the data source.
cPassword - Specifies the password to the data source.
cConnectionName - Specifies a named connection created with CREATE CONNECTION.
Note that this command can fail to use a trusted connection in some scenarios (I've seen it on a Win95 box), even if the DSN is set up to use NT authentication. To get around this, use the VFP Command SQL String Connect and pass Trusted_Connection=Yes as part of the connect string. - Andrew Coates
When I first started playing with this I wrote a unit test to find out what would happen if by chance the wrong userid and/or password were passed in, ie someone without a trusted relationship were running the system. What happens is that the user is given a really ugly message screen and is prompted to select the correct DSN. I don't know about you ... but my users wouldn't have a clue! I dug around for the better part of a day trying to figure out what I could do to stop the prompt from coming up because I didn't realize that you can use SQLSetProp()function to define default behaviour if you use 0 (zero) as the connection handle parameter in the function.

*!* Do not display a login


So what was the result of this change? No error message and the login screen came up? -- Bob Archer

You know it has been awhile since I posted this I don't remember whether there was an error raised or not. I am doing things a little differently now and using a DSNLess Connections. However, I recall that the SQL DSN selection screen was suppressed quite nicely. ?cs

Pretty sure VFP's Sql Connect() returns -1, and aError() will say something about "bad user/pass" - ?cfk
The code will suppress the login box and allow the connection to either connect or fail without user interaction. -DH

Category VFP Commands, Category Client / Server, Category DSNLess Connections
( Topic last updated: 2008.03.06 09:35:13 AM )