Also I think the SQL_Connect() returning a handle and it not being closed or something is causing the memory leak. Either way, if you move to SQL_TQuery, you prevent server lag and all the handles are automatically closed for you when the query callback finishes. It's a win-win.