Some said that this might be caused by mismatching data and its type, yet there is no data table in my database.
My codes are:
int main(){
_ConnectionPtr ptr_database = NULL;
CoInitialize(NULL);
HRESULT hr = ptr_database.CreateInstance(__uuidof(Connection));
if (FAILED(hr)) {
_com_error e(hr);
MessageBox(NULL, e.ErrorMessage(), "警告1", MB_OK | MB_ICONINFORMATION);
return -1;
}
_bstr_t str_connect ("Data Source = DESKTOP-Q472AQO\\SQLSERVER; \
Provider = SQLOLEDB.1; Integrated Security = False; Persist Security Info = True; \
User ID = UserForIndoorModel; Password = 30624770; Initial Catalog = IndoorModel");
try {
ptr_database->Open(str_connect, "", "", adConnectUnspecified);
}
catch(_com_error &e) {
MessageBox(NULL, e.Description(), "警告2", MB_OK | MB_ICONINFORMATION);
return -1;
}
return 0;
}
The error happens at the second MessageBox with "警告2". Is there any wrong with my str_connect?
(I have authorize the user and the password is right.)