Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
List Of SQL Servers
Message
From
18/12/2006 06:22:28
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01178456
Message ID:
01178504
Views:
16
Hi Kevin,

Here's some code that I adjusted from the data explorer in VFP, you pass in a the name of a cursor that already exists (or you could adjust the code to suit how you want to store the list):
CREATE CURSOR c_Servers;
	(cServerName C(100))
LPARAMETERS tcCursor

* Populate collection with available SQL servers
#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";

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

ZAP IN (m.tcCursor)

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
						*!*									oServerCollection.AddEntity(aServerList[i])
						INSERT INTO (m.tcCursor) (cServerName) VALUES (RTRIM(aServerList[i]))
					ENDFOR
				ENDIF
			ENDIF
		ENDIF
	ENDIF
CATCH TO oException
	* ignore error, just return an empty collection of servers
	MESSAGEBOX(oException.Message, 0+16, _screen.caption)
FINALLY
	IF hConn <> 0
		SQLFreeHandle(SQL_HANDLE_DBC, hConn)
	ENDIF
	IF hEnv <> 0
		SQLFreeHandle(SQL_HANDLE_ENV, hConn)
	ENDIF
ENDTRY
>How can I return a list of SQL servers in VFP?
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform