Welcome to the forums. I have two suggestions, but they may not be ideal:

1) You can just open one connection, and leave it open for the duration. There is no need to close it, and that alone should speed up the processing. Just keep changing the command.CommandText to the new query, without ever closing the connection. I guess I'd have to see some code to make a verys specific suggestion there.

2) I'm not sure what the slowest part of the process is. You might benefit from a stored procedure handling the INSERT, but failing that, why not lump several INSERT statements together. Shoudl be able to separate them with commas. If you tested for five numbers, then lumped (up to) five INSERT statements together, that should speed things up some. Further improvements might be made along these lines, such as searching until five numbers need to be inserted, then inserting them. Etc.