Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Jerzy Kopinski
  Where is Jerzy Kopinski?
 Pruszcz Gdanski
 Poland
 Jerzy Kopinski
 Tags
Subject: Def. ODBC data source FROM VFP Apps
Thread ID: 395943 Message ID: 395943 # Views: 51 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Win32API programming
Date: Tuesday, January 21, 2014 5:36:44 PM         
   


Hi,
In my VFP app I try to define programaticaly a new ODBC data source for SQL Server using Win API (Windows 7 prof. 32 bit).
Unfortunatelly all my attempts failed and the question is: what is wrong? May be some of our experts knows the answer?
The code is below:


LOCAL nSQLHandle, cConnectionString, cConnection, cDataSource, cSQL, loExc as Exception ;
cSQLDriver, cSQLServer, cSQLAttributes, cDSNDescription, cDSNName, cDBName, ln

*- values for fRequest
#DEFINE ODBC_ADD_DSN 1        		&& Add data source
#DEFINE ODBC_CONFIG_DSN 2     		&& Configure (edit) data source
#DEFINE ODBC_REMOVE_DSN 3     		&& Remove data source
#DEFINE ODBC_ADD_SYS_DSN 4		&& Add a new system data source. 
#DEFINE ODBC_CONFIG_SYS_DSN 5 		&& Modify an existing system data source. 
#DEFINE ODBC_REMOVE_SYS_DSN 6		&& Remove an existing system data source. 
#DEFINE ODBC_REMOVE_DEFAULT_DSN 7	&& Remove the default data source specification section from the system information.


DECLARE INTEGER SQLConfigDataSource IN ODBCCP32.DLL ;
	INTEGER hwndParent, INTEGER fRequest, ;
	STRING lpszDriver, STRING lpszAttributes
 
 *- lpszDriver is an SQL Driver name 'SQL Driver'
 
 cSQLDriver = 'SQL Server'+CHR(0)
 cSQLServer = 'HOST\SQLEXPRESS'
 cDSNDescription = 'SQL_tmp'
 cDSNName = 'SQL_tmp'
 cDBName=''
 

 cSQLAttributes='Server='+cSQLServer+CHR(0)+;
 	'Description='+cDSNDescription+CHR(0)+;
 	'DSN='+cDSNName+CHR(0)+;
 	IIF(!EMPTY(cDBName),'Database='+cDBName+CHR(0),'')+;
 	'Regional=Yes'+CHR(0)+;
 	'Trusted_Connection=Yes'+CHR(0)
 	
ln = SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, cSQLDriver, cSQLAttributes)

IF ln<>0
	MESSAGEBOX("DSN Created")
ELSE
	MESSAGEBOX("DSN not created")
ENDIF


ENTIRE THREAD

Def. ODBC data source FROM VFP Apps Posted by Jerzy Kopinski @ 1/21/2014 5:36:44 PM
RE: Def. ODBC data source FROM VFP Apps Posted by Stefan Wuebbe @ 1/21/2014 5:58:47 PM
RE: Def. ODBC data source FROM VFP Apps Posted by Jerzy Kopinski @ 1/22/2014 7:34:23 AM
RE: Def. ODBC data source FROM VFP Apps Posted by Stefan Wuebbe @ 1/22/2014 8:27:23 AM
RE: Def. ODBC data source FROM VFP Apps Posted by Jerzy Kopinski @ 1/22/2014 8:52:22 AM
RE: Def. ODBC data source FROM VFP Apps Posted by Jerzy Kopinski @ 1/22/2014 8:36:09 AM
RE: Def. ODBC data source FROM VFP Apps Posted by Stefan Wuebbe @ 1/22/2014 9:08:24 AM
RE: Def. ODBC data source FROM VFP Apps Posted by tom knauf @ 1/23/2014 1:23:01 PM