I've done this type of app before.

Its easier to maintain an array of connected clients in the server, instead of going into the db everytime a message is sent. In my opinion, the sock(this number) should not be related to anything in the database. This index is always going to be different for each client, each time they connect, because its based on who connects first. I dont think there is any need to base it on the ID of the clients info in the database.

Its easier to keep an array of users connected. So it would go like this:

Client1 sends "hello" to Client2
Server receives "hello,Client2" from Client1, it parses the message and can see that its destined for Client2
Server searchs the array of connectes clients looking for "Client2" in the list
Server finds "Client2" at array #X, it then sends the message to Winsock(X).

You see? If you keep the socket index matching the index of the client in the array, you can make this very easy for yourself