Every so often someone asks on either an internal alias or our public newsgroup about the right way to establish a data connection using the Compact Framework. Most of the time you don’t have to do this since many of the built-in classes will bring up the connection automatically, but sometimes it’s necessary.
The API to use is called ConnMgrEstablishConnection(), and normally you’d P/Invoke to it to do all the magic. But there’s a better way! The fine folks at OpenNETCF.org have a complete class library for interacting with Connection Manager as part of their Smart Device Framework. You can use the library to not only open or close connections, but also to listen for events like Connected, Disconnected, and ConnectionFailed.
[Author: Neil Enns]