Call now: (800) 766-1884  



 Home


 SQL Server Tips
 SQL Server Training

 SQL Server Consulting
 SQL Server Support
 SQL Server Remote DBA



 Articles
 Services
 SQL Server Scripts
 Scripts Menu



 

 

 

 
 

SQL Server

SQL Server Tips by Gama and Naughter Consulting

 


Adding XP Support

To allow the code to be called from SQL Server as an XP, we will use the XP++ framework to implement the boilerplate code and then call the “IcmpServerReachable” function just like we did for the COM support. We follow the procedure for adding XP++ support to our project as described in the XP++ chapter. Some issues, which crop up are:

      * When we add the “XP_PP.h” and XP_PP.cpp” modules to the project and then try to do a build, you will get an compiler warning about C++ exceptions being used in the code but the project settings not containing this. This is because the default project settings provided for a new ATL project in Visual C++ v6 does not enable exceptions to save a few kilobytes in the final DLL size. To change this we enable the exception handling check box in the “C++ Language” category on the C++ tab for the project settings.

      * You should also include “new” and “srv.h” into the pre-compiled header to avoid warnings from the XP++ framework.

     * Because we use some of the C runtime functions in the XP, we need to remove the “_ATL_MIN_CRT” pre-processor define from the project’s C++ compiler settings. If you are using a newer copy of Visual Studio, then you will not need to do this because the ATL wizards do not have this value set by default.

The XP code for XP_SERVERREACHABLE is implemented in the XPServerReachable module and contains the following code:

XPServerReachable.h

#ifndef __XPSERVERREACHABLE_H__

#include "..\xp++\xp_pp.h"

class CServerReachableStoredProcedure : public CExtendedStoredProcedure
{
public:
virtual void DisplayUsage();
virtual BOOL Run();
DECLARE_XP_PARAMETERS()
};

#endif //__XPSERVERREACHABLE_H__

XPServerReachable.cpp

#include "stdafx.h"
#include "XPServerReachable.h"
#include "PingMachine.h"

IMPLEMENT_VERSION_XP()
IMPLEMENT_XP(XP_SERVERREACHABLE, CServerReachableStoredProcedure)

#define SERVER_INDEX 0
#define REACHABLE_INDEX 1

BEGIN_IMPLEMENT_XP_PARAMETERS(CServerReachableStoredProcedure)
XP_INPUT_PARAMETER (1, NULL, XP_ALLOW_BIGVARCHAR | XP_ALLOW_BIGCHAR | XP_ALLOW_TEXT | XP_ALLOW_VARCHAR | XP_ALLOW_NTEXT | XP_ALLOW_NVARCHAR, FALSE, FALSE, XP_PT_TTEXT)
XP_OUTPUT_PARAMETER(2, NULL, XP_PT_BIT | XP_ALLOW_INT1 | XP_ALLOW_INT2 | XP_ALLOW_INT4, TRUE, FALSE)
END_IMPLEMENT_XP_PARAMETERS(CServerReachableStoredProcedure)

void CServerReachableStoredProcedure::DisplayUsage()
{
SendInfoMsg("USAGE: XP_SERVERREACHABLE @Server, @Reachable OUTPUT");
}

BOOL CServerReachableStoredProcedure::Run()
{
XP_ASSERT(m_pParameterData);

char szErrorMsg[2048];

BOOL bSuccess = FALSE;

TCHAR* pszServer = XP_TTEXT(m_pParameterData[SERVER_INDEX].m_Data);
BOOL bReachable = IcmpServerReachable(pszServer);

int nConvertedDataSize = Convert(SRVINT4, &bReachable, sizeof(bReachable), m_pParameterData[REACHABLE_INDEX].m_bType, m_pParameterData[REACHABLE_INDEX].m_pData, m_pParameterData[REACHABLE_INDEX].m_cbMaxLen);
if ((nConvertedDataSize > 0))
{
bSuccess = (ParamSetOutput(REACHABLE_INDEX+1, m_pParameterData[REACHABLE_INDEX].m_pData, nConvertedDataSize, FALSE) == SUCCEED);
}
else
{
sprintf(szErrorMsg, "%s: Failed to convert the verified value to the required output type, Error:%d", m_szFunctionName, GetLastError());
SendErrorMsg(szErrorMsg);
}

return TRUE;
}


The above book excerpt is from:

Super SQL Server Systems
Turbocharge Database Performance with C++ External Procedures

ISBN: 0-9761573-2-2
Joseph Gama, P. J. Naughter

 http://www.rampant-books.com/book_2005_2_sql_server_external_procedures.htm

 


 

 

 

Burleson Consulting Remote DB Administration


 

 


 

 

 

 

 
Burleson is the America's Team

Note: The pages on this site were created as a support and training reference for use by our staff of DBA consultants.  If you find it confusing, please exit this page.

Errata?  SQL Server technology is changing and we strive to update our SQL Server support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:and include the URL for the page.
 


Burleson Consulting
SQL Server database support

 

Copyright © 1996 -  2013 by Vaaltech Web Services. All rights reserved.

Hit Counter