I want to insert a row in CA table rather than using
CScript and WinRunSQl.vbs i want to write my own C++ code to do that.
I did in the following way
void ExecuteQueryForInsertIntoMSIDB()
{
PMSIHANDLE hDatabaseForInsert = 0;
PMSIHANDLE hViewForInsert = 0;
PMSIHANDLE hRecForInsert = 0;
if (ERROR_SUCCESS == MsiOpenDatabase(_T("C:\\Install.msi"),
MSIDBOPEN_TRANSACT, &hDatabaseForInsert))
{
if (ERROR_SUCCESS == MsiDatabaseOpenView(hDatabaseForInsert, _T("INSERT
INTO 'CustomAction'('Action','Type','Source','Target') VALUES ('', 1
,'','InstallCopy')"), &hViewForInsert))
{
hRecForInsert = MsiCreateRecord(1);
if (ERROR_SUCCESS == MsiViewExecute(hViewForInsert, hRecForInsert)
&& ERROR_SUCCESS == MsiViewClose(hViewForInsert)
&& ERROR_SUCCESS == MsiDatabaseCommit(hDatabaseForInsert))
{
//
// New data successfully committed to the database
//
}
}
}
}
But i am not able to see any row in the CA table. Can some suggest me what i
am doing wrong here?
hRecForInsert = MsiCreateRecord(1);
I just added, i tried without this line of code also it gives me the same
error
Regards,
Amar.
> if (ERROR_SUCCESS == MsiDatabaseOpenView(hDatabaseForInsert, _T("INSERT
> INTO 'CustomAction'('Action','Type','Source','Target') VALUES ('', 1
> ,'','InstallCopy')"), &hViewForInsert))
That should be `CustomAction` rather than 'CustomAction'.
Likewise in the column names.
And don't leave CustomAction.Action empty.
Errors like this should cause MsiDatabaseOpenView or
MsiViewExecute to return something other than ERROR_SUCCESS,
I think. Your source code does check for errors
but I don't see anything there to report the errors it finds.
Thus, I suspect one of the calls returned an error
but you didn't know about it. Did you step through the code
with a debugger, to see how far it gets?
Thank you for your response. It worked fine while debugging.
But when i do the same in release mode it is not working. I am doing this as
a post build event. Why that is not working in release mode i am confused and
trying, no idea, can you please suggest me?
Amar.
"Amar" <Am...@discussions.microsoft.com> wrote in message
news:239C7F0A-AC9C-45A6...@microsoft.com...
I added the error code also to debug and test.
What exactly is happening here is. If i do F5 and debug the code step by
step it works without any problem. But when i do build in debug mode without
debugging it is not updating the msi with the values what i want to enter. i
am executing the below mentioned code as a post build event.
Why is that so?
Amar
Thanks for your suggestions. It worked find now in both release and debug
modes, i did a small change in settings which created all these problems.
Thanks again.
Amar