Looks like SQL_Connect() returned an invalid handle, meaning that connection couldn't be made. You should check if the returned handle ("sql" variable) is valid before doing anything with it. You can also print the error that's stored into "error" variable.