Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to get all the data sources available?
Message
 
À
25/03/1999 12:44:51
Bob Lucas
The WordWare Agency
Alberta, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00201880
Message ID:
00201940
Vues:
10
>>Hi,
>>
>>Is it possible to produce an array filled with data sources available for specific ODBC driver. It may help me to set a connection property "DataSource" for my generic connection in a database container.
>
>here is code I use to filter to SQL Server datasources. It is a method in my application object. The filter property is this.cDataSourceFilter and would have a value "SQL Server". This could be changed or removed.
>
>The application object has an array this.aSQLDataSources that stores the list of valid ODBC data sources for the filter used.
>
>
>#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

Thank you very much. I'll give it a try.
Igor Gelin
Database Developer
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform