Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to specify ODBC connection in EXE?
Message
From
14/10/1998 12:41:06
Bob Lucas
The WordWare Agency
Alberta, Canada
 
 
To
14/10/1998 12:31:13
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00146099
Message ID:
00146719
Views:
32
>Thanks for the reply. I have a few follow-up questions. I'm a newcomer to SQL Server so these questions may be real basic.
>
>>On my login form, there is a dropdown combo list that displays all of the available ODBC connections on the user machine. I have these filtered to SQL Server types.
>
>I'm assuming your login form is a VFP form you created. How do you populate the record source of the list?
>
>>For SQL Server, I have an automatic process to add a new data source based on small REG file.
>
>Is a REG file something you wrote or something that is a part of ODBC?
>Is there a way to invoke the ODBC wizzard from VFP 6?
>
>Thanks,
>John

I populate the source of the combobox by reading the registry. I have a method in my global application object that loads this info into an array that is also a property of my global application object.

Here is the code:
#DEFINE SQL_FETCH_NEXT 1 
#DEFINE SQL_FETCH_FIRST 2 
#DEFINE SQL_SUCCESS 0 
#DEFINE MAX_STRING 128 

LOCAL j

WAIT WINDOW "Loading Data Sources..." NOWAIT

DECLARE INTEGER SQLDataSources IN ODBC32.DLL ; 
   INTEGER henv, SHORT fdirection, ;
   STRING @szDSN, INTEGER cbDSNMax, ;
   INTEGER @pcbDSN, STRING @szDescription, ;
   INTEGER cbDescriptionMax, INTEGER @pcbDescriptionn

hEnv = VAL(SYS(3053))      && The hEnv (converted to a number)
cbDsnMax = MAX_STRING      && How long can the DSN Name be?
pcbDSN = 0                 && How many were actually returned



cbDescriptionMax = MAX_STRING && How long can the description be? 

pcbDescriptionn = 0            && How long the description actually was

fDirection = SQL_FETCH_FIRST     && The first time start at the top
retVal = SQL_SUCCESS             && Start with no errors
j = 1


DO WHILE (retVal = SQL_SUCCESS) 
   szDsn = SPACE(MAX_STRING+1)   && Make sure there is enough space
   szDescription = SPACE(MAX_STRING+1)

   retval = SQLDataSources(hEnv, fDirection, ;
                  @szDSN, cbDSNMax, @pcbDSN, ;
                  @szDescription, cbDescriptionMax, @pcbDescriptionn)
                  
  retval = IIF(EMPTY(LEFT(szDSN, pcbDSN)), -1, SQL_SUCCESS)
	*-- add to the array if the data source matches    
	
	IF retval = SQL_SUCCESS AND ;
		ALLTRIM(UPPER(this.cDataSourceFilter)) $ ;
		UPPER(ALLTRIM(LEFT(szDescription, pcbDescriptionn)))
		              
		DIMENSION this.aSQLDataSources[j, 2]
		this.aSQLDataSources[j, 1] = LEFT(szDSN, pcbDSN)
		this.aSQLDataSources[j, 2] = LEFT(szDescription, pcbDescriptionn)
		j = j + 1
	ENDIF	

   * We only want to do the SQL_FETCH_FIRST the first time
   fDirection = SQL_FETCH_NEXT
ENDDO 

WAIT CLEAR
RETURN IIF(TYPE("this.aSQLDataSources[1, 1]") = "C", .t., .f.)
Note that I filter on a property called this.cDataSourceFilter. This is set to "SQL Server" so that only SQL Server ODBC data sources will show up in the combo box.
Previous
Reply
Map
View

Click here to load this message in the networking platform