Call now: (800) 766-1884  


 SQL Server Tips
 SQL Server Training

 SQL Server Consulting
 SQL Server Support
 SQL Server Remote DBA

 SQL Server Scripts
 Scripts Menu




  SQL Server Tips by Gama and Naughter


This is the corollary function to XP_INI_WRITESTRING. The underlying SDK function used is “GetPrivateProfileString”. This XP takes 5 parameters, namely the ini filename, the section to use, the key to read from, the default value to return if not found and finally the actual output parameter, which contains the string that was read. Because we are reading in data, we need to allocate memory to store the received data. This is handled using appropriate exception handling to catch memory allocation failures. We also need to handle the fact that we do not know the full size of the string value we are reading a priori. We achieve this by first calling the “GetPrivateProfileString” function with an initial buffer size of 1 kilobyte and if the function fails due to lack of buffer space then we retry the function using a buffer size which is doubled. When the function eventually succeeds the string data read is returned in the output parameter using “CExtendedStoredProcedure::ParamSetOutput”. The code also looks at the data type of the output parameter to ensure it handles differences between UNICODE and ASCII strings.

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  



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