Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Trying to prototype SQLDataSource


2 replies to this topic

Ozone

Ozone
  • Full Members
  • 77 posts

Posted 18 October 2006 - 20:45

Has anyone on this board successfully prototyped SQLDataSources in ODBC32.DLL? This prototype is not in Winapi.h, so I need to make one.

The return value is suppose to be '1' upon success, but I always get '65534' when it is called.

Below is the InstallScript prototype I am currently working with:

// --- API call to "SQLDataSources" in ODBC32.DLL
prototype ODBC32.SQLDataSources (HWND, NUMBER, BYVAL STRING, NUMBER, NUMBER, BYVAL STRING, NUMBER, NUMBER);

Below is the MicroSoft explanation of the format:

SQLRETURN SQLDataSources(
SQLHENV EnvironmentHandle,
SQLUSMALLINT Direction,
SQLCHAR * ServerName,
SQLSMALLINT BufferLength1,
SQLSMALLINT * NameLength1Ptr,
SQLCHAR * Description,
SQLSMALLINT BufferLength2,
SQLSMALLINT * NameLength2Ptr);

I have successfully run the following prototype in Visual Basic 6.0:

Private Declare Function SQLDataSources Lib "ODBC32.DLL" (ByVal henv&, ByVal fDirection%, ByVal szDSN$, ByVal cbDSNMax%, pcbDSN%, ByVal szDescription$, ByVal cbDescriptionMax%, pcbDescription%) As Integer

Any brave souls out there?


Ozone

Ozone
  • Full Members
  • 77 posts

Posted 19 October 2006 - 16:09

By trial and error, I have the working prototype! (more error than trial)

prototype ODBC32.SQLDataSources (BYVAL HWND, INT, BYREF STRING, INT, BYREF INT, BYREF STRING, INT, BYREF INT);

I need to buy a lottery ticket today!

smile.gif

Ozone

Ozone
  • Full Members
  • 77 posts

Posted 19 October 2006 - 17:18

The code for those of you who want a working model....

CODE
////////////////////////////////////////////////////////////////////////////////
//
//    Purpose:  To get DSN's
//
//    Last Updated:  10-17-2006 - OZONE - Created
//
////////////////////////////////////////////////////////////////////////////////

// --- API call to "SQLDataSources" in ODBC32.DLL
prototype ODBC32.SQLDataSources (BYVAL HWND, INT, BYREF STRING, INT, BYREF INT, BYREF STRING, INT, BYREF INT);

// --- API call to "SQLAllocEnv" in ODBC32.DLL
prototype ODBC32.SQLAllocEnv (BYREF HWND);

// -- Prototype this Function
prototype Get_DSNs();

#define SQL_SUCCESS     0
#define SQL_FETCH_NEXT  1

// -- Begin function here
function Get_DSNs()

INT   i, iDSNLen, iDRVLen;
STRING  sDSNItem[1024], sDRVItem[1024];
STRING sDSN, sDRV;
HWND    lHenv;

begin
     
//--- get the DSNs
   if SQLAllocEnv(lHenv) != -1 then
       while i = SQL_SUCCESS
           i = SQLDataSources(lHenv, SQL_FETCH_NEXT, sDSNItem, 1024, iDSNLen, sDRVItem, 1024, iDRVLen);
           StrSub ( sDSN, sDSNItem, 0, iDSNLen );
           StrSub ( sDRV, sDRVItem, 0, iDRVLen );

           // Filter the type of database that you want to display
           if sDRV = "Pervasive ODBC Engine Interface" then
   MessageBox( "DRIVER = " + sDRV + "\n\nDSN = " + sDSN , INFORMATION);    
           elseif sDRV = "SQL Server" then
   MessageBox( "DRIVER = " + sDRV + "\n\nDSN = " + sDSN , INFORMATION);    
           elseif sDRV = "Microsoft ODBC for Oracle" then
   MessageBox( "DRIVER = " + sDRV + "\n\nDSN = " + sDSN , INFORMATION);    
           endif;
       endwhile;            
   endif;    

end;