Remsor,
I've always just used a udl file in the past (similar to the approach Mike outlined). So, your question intrigued me since there has to be a way to do it from code. As I suspected it is a pretty straight forward and simple API call. I've worked up a little program below to show how it is done. Cut-n-paste the code below into a prg file and run it from within VFP.
PUBLIC oForm
oForm = CREATEOBJECT("clsvfpdsn"

oForm.show()
DEFINE CLASS clsvfpdsn AS form
Top = 0
Left = 0
Height = 92
Width = 309
DoCreate = .T.
Caption = "VFP CREATED DSN"
WindowType = 1
Name = "Form1"
AutoCenter = .T.
ADD OBJECT command1 AS commandbutton WITH ;
Top = 45, ;
Left = 37, ;
Height = 27, ;
Width = 100, ;
Caption = "Add DSN", ;
Name = "Command1"
ADD OBJECT command2 AS commandbutton WITH ;
Top = 45, ;
Left = 171, ;
Height = 27, ;
Width = 100, ;
Caption = "Remove DSN", ;
Name = "Command2"
ADD OBJECT check1 AS checkbox WITH ;
Top = 19, ;
Left = 37, ;
Height = 17, ;
Width = 82, ;
AutoSize = .T., ;
BackStyle = 0, ;
Caption = "Silent Mode", ;
Value = 1, ;
Name = "Check1"
PROCEDURE Load
DECLARE INTEGER SQLConfigDataSource IN odbccp32;
INTEGER hwndParent,;
INTEGER fRequest,;
STRING lpszDriver,;
STRING lpszAttributes
ENDPROC
PROCEDURE command1.Click
#DEFINE ODBC_ADD_DSN 1
*!* #DEFINE ODBC_CONFIG_DSN 2
*!* #DEFINE ODBC_REMOVE_DSN 3
Local nReturnValue, cDriver, cAttribs
cDriver = "SQL Server"
cAttribs = "SERVER=SomeServer" + Chr(0)
cAttribs = cAttribs + "DESCRIPTION=Temporary DSN created with VFP code" + Chr(0)
cAttribs = cAttribs + "DSN=VFP_CREATED_DSN" + Chr(0)
cAttribs = cAttribs +"DATABASE=pubs" + Chr(0)
IF thisform.check1.value = 0
nReturnValue = SQLConfigDataSource(thisform.hwnd, ODBC_ADD_DSN, cDriver, cAttribs)
ELSE
nReturnValue = SQLConfigDataSource(0, ODBC_ADD_DSN, cDriver, cAttribs)
ENDIF
If nReturnValue = 1
Messagebox("VFP_CREATED_DSN Created",64,"SUCCESS"

Else
Messagebox("Creation of VFP_CREATED_DSN Failed",64,"FAILURE"

Endif
ENDPROC
PROCEDURE command2.Click
#DEFINE ODBC_REMOVE_DSN 3
*!* #DEFINE ODBC_ADD_DSN 1
*!* #DEFINE ODBC_CONFIG_DSN 2
Local nReturnValue, cDriver, cAttribs
cDriver = "SQL Server"
cAttribs = "DSN=VFP_CREATED_DSN" + Chr(0)
IF thisform.check1.value = 0
nReturnValue = SQLConfigDataSource(thisform.hwnd, ODBC_REMOVE_DSN, cDriver, cAttribs)
ELSE
nReturnValue = SQLConfigDataSource(0, ODBC_REMOVE_DSN, cDriver, cAttribs)
ENDIF
If nReturnValue = 1
Messagebox("VFP_CREATED_DSN Deleted",64,"SUCCESS"

Else
Messagebox("Deletion of VFP_CREATED_DSN Failed",64,"FAILURE"

Endif
ENDPROC
ENDDEFINE
Slighthaze =
NULL
[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]