small amount of water and sand in the dock connector,
small amount of sand and water got into my iPhone 4's dock connector. Now i keep getting the following massage "This Accessory is not optimized for this iPhone",
there is nothing plugged in. Do i need to replace the the dock connector or is there other options?
i would first recommend cleaning out the sand as soon as you can. From the looks of it, the sand that you ahve in there is shorting out the connector and it thinks that you plugged it into something.
Once you are certain that it's completely dry, useing a can of compressed air, carefully blow out the sand. you can also use a plastic spudger (like the one sold here Spudger) to carefully remove the sand. i do not recommend anything metal as that may cause more damage if you short out anything else. I do recommend first to turn off the phone while this is happening, or better yet, remove the dock connector from the iPhone by following the guide here Installing iPhone 4 Dock Connector
it's not an easy repair but you might need to replace the dock connector if you cannot get the sand out or if the error does not go away.