If you're trying to write something for a TSRP server, ARP is probably the better way to go because it has a complete API making it easier to develop stuff. The thing you're trying to do can probably be automated by the natives supplied in the data layer, so you'll never need to access the SQL database. The data layer is an API which allows you to manipulate and save a keytable into SQL automatically. My description may be simplifying it because it does much more than that, but that's all you really need to know for now. If you're interested or want to know more about it, feel free to post on the ARP board.
EDIT: Your loss. I tried to help. It's the best solution, but if you want to make more crap code like Harbu then be my guest.