Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQLSMO for SQL server 2005
Message
From
18/10/2006 08:48:00
 
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Miscellaneous
Thread ID:
01162809
Message ID:
01162881
Views:
75
Hi Shawn,

I just did this by looking at the code in the dataexplorer.app (I think it was in the datamgmt_sql.prg). Basically you use some Windows APIs to get the list.

Here's my adjusted code:
* 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
						?(RTRIM(aServerList[i]))
					ENDFOR
				ENDIF
			ENDIF
		ENDIF
	ENDIF
CATCH TO oException
	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
>Hi all, it has been forever since i posted here, I finally got a gig doing VFP work again, yeaaahhh ha!
>
>Time for the question currently the product use SQLDMO to list all the servers that the user can connect to. This no longer works with SQL Server 2005.
>
>Has anyone had any luck with connecting to SQLSMO to get the list of databases?
>
>TIA
>
>Shawn
Frank.

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

Click here to load this message in the networking platform