Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Vladimir Zografski
  Where is Vladimir Zografski?
 Sofia
 Bulgaria
 Vladimir Zografski
 To: Gianni Sassanelli
  Where is Gianni Sassanelli?
 Rome
 Italy
 Gianni Sassanelli
 Tags
Subject: RE: enumerate INSTALLED SQL Innstance
Thread ID: 228265 Message ID: 228438 # Views: 1 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Databases, Tables and SQL Server
Date: Monday, May 18, 2009 10:18:57 PM         
   


> Hi,
> I found the following code that solve my problem and post it for all.
>
> Gratings to Craig Bailey for this fine work!
>
> bye
>
>
> #Define SQL_HANDLE_ENV 1
> #Define SQL_HANDLE_DBC 2
> #Define SQL_ATTR_ODBC_VERSION 200
> #Define SQL_OV_ODBC3 3
> #Define SQL_SUCCESS 0
> #Define SQL_NEED_DATA 99
> #Define DEFAULT_RESULT_SIZE 2048
> #Define SQL_DRIVER_STR "DRIVER=SQL SERVER"
> 
> set step on
> Local hEnv
> Local hConn
> Local cInString
> Local cOutString
> Local nLenOutString
> Local Array aServerList[1]
> 
> Declare SHORT SQLBrowseConnect In odbc32 ;
> 	INTEGER ConnectionHandle, ;
> 	STRING InConnectionString, ;
> 	INTEGER StringLength1, ;
> 	STRING @ OutConnectionString, ;
> 	INTEGER BufferLength, ;
> 	INTEGER @ StringLength2Ptr
> 
> Declare SHORT SQLAllocHandle In odbc32 ;
> 	INTEGER HandleType, ;
> 	INTEGER InputHandle, ;
> 	INTEGER @ OutputHandlePtr
> 
> Declare SHORT SQLFreeHandle In odbc32 ;
> 	INTEGER HandleType, ;
> 	INTEGER Handle
> 
> Declare SHORT SQLSetEnvAttr In odbc32 ;
> 	INTEGER EnvironmentHandle, ;
> 	INTEGER Attribute, ;
> 	INTEGER ValuePtr, ;
> 	INTEGER StringLength
> 
> 
> 
> hEnv = 0
> hConn = 0
> cInString = SQL_DRIVER_STR
> cOutString = Space(DEFAULT_RESULT_SIZE)
> 
> nLenOutString = 0
> 
> Local cServerList
> cServerList = ''
> 
> Try
> 	If SQLAllocHandle(SQL_HANDLE_ENV, hEnv, @hEnv) == SQL_SUCCESS
> 		If (SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, SQL_OV_ODBC3, 0)) == SQL_SUCCESS
> 			If SQLAllocHandle(SQL_HANDLE_DBC, hEnv, @hConn) == SQL_SUCCESS
> 				IF SQLBrowseConnect(;
> 					hConn, @cInString, Len(cInString), @cOutString,;
> 					DEFAULT_RESULT_SIZE, @nLenOutString)	 == SQL_NEED_DATA
> 					
> 					nCnt = Alines(aServerList, Strextract(cOutString, '{', '}'), .T., ',')
> 					For i = 1 To nCnt
> 						cServerList = cServerList + ',' + Alltrim(aServerList[i])
> 					Endfor
> 				Endif
> 			Endif
> 		Endif
> 	Endif
> Catch To oException
> * ignore error, just return an empty string of servers
> Finally
> 
> 	If hConn <> 0
> 		SQLFreeHandle(SQL_HANDLE_DBC, hConn)
> 	Endif
> 	If hEnv <> 0
> 		SQLFreeHandle(SQL_HANDLE_ENV, hConn)
> 	Endif
> Endtry
> ?cServerList
> 


Just take a look at the datamgmt_sql.prg
It's part from dataexplorer.pjx

Vladimir Zografski
Systems Analyst

ENTIRE THREAD

enumerate INSTALLED SQL Innstance Posted by Gianni Sassanelli @ 5/17/2009 1:26:55 PM
RE: enumerate INSTALLED SQL Innstance Posted by Gianni Sassanelli @ 5/17/2009 9:20:00 PM
RE: enumerate INSTALLED SQL Innstance Posted by Vladimir Zografski @ 5/18/2009 10:18:57 PM