Sometimes you need to use the connection string in the program, but it is possible to change it when configured, manually input is easy, with this dialog, everything is simple, but this dialog is not an API. In addition, I checked the MSDN and copying the West and copied the cop and copying myself. I have been in some of the following functions. The thing inside does not need to understand, put it with your Copy, you can use it, you can understand the best, find your mistake, please send emailto: fantong77@hotmail.com.
BOOL GetConnectString (TCHAR * lpszConnectString, HWND hWndParent) {CComPtr
// Prompt the user for the provider and initialization properties hr = pIDBPromptInitialize-> PromptDataSource (NULL, hWndParent, DBPROMPTOPTIONS_PROPERTYSHEET, 0, NULL, NULL, IID_IDBProperties, (IUnknown **) & pIDBProperties);. If (FAILED (hr)) return FALSE ; hr = CoCreateInstance (CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, IID_IDataInitialize, (void **) & spDataInit); if (FAILED (hr)) return FALSE; hr = spDataInit-> GetInitializationString (pIDBProperties, true, & bstrConnectString); if (FAILED (hr )) RETURN FALSE; LSTRCPY (LpszConnectString, (Char *) _ BSTR_T (BSTRCONNECTSTRING); RETURN TRUE;
}
Parameter description, the return value is false, the user cancels
The second is OUT, enter the connection string
Third place in, parent window
Remember to initialize COM first