Unsaved Changes
Feb 14, 2008i used following code to create atable on ssce 3.5 database, but there is something wrong and i dont know what? the problem is all the results is S_OK but ssce does not create the table on the database, the interesting point is, if i connect the same database with vs2008 server explorer and execute the code, ssce succesfully creates the table, my mind is totally screwed up...
[CODE]
wstring cmd;//contains create table command;
HRESULT hr = NOERROR;
DBPROPSET dbpropset[2];
DBPROP dbprop[1];
DBPROP sscedbprop[1];
IDBInitialize * pIDBInitialize = NULL;
IDBProperties * pIDBProperties = NULL;
IDBCreateSession *m_pIDBCreateSession;
IDBCreateCommand *pIDBCrtCmd = NULL;
ICommandText *pICmdText = NULL;
hr = CoCreateInstance(CLSID_SQLSERVERCE, 0, CLSCTX_INPROC_SERVER,
IID_IDBInitialize, (void**) &pIDBInitialize);
VariantInit(&dbprop[0].vValue);
VariantInit(&sscedbprop[0].vValue);
dbprop[0].dwPropertyID = DBPROP_INIT_DATASOURCE;
dbprop[0].dwOptions = DBPROPOPTIONS_REQUIRED;
dbprop[0].vValue.vt = VT_BSTR;
dbprop[0].vValue.bstrVal = SysAllocString(L"NewDatabase.sdf");
sscedbprop[0].dwPropertyID = DBPROP_SSCE_DBPASSWORD;
sscedbprop[0].dwOptions = DBPROPOPTIONS_REQUIRED;
sscedbprop[0].vValue.vt = VT_BSTR;
sscedbprop[0].vValue.bstrVal = SysAllocString(L"<enterStrongPasswordHere>");
dbpropset[0].guidPropertySet = DBPROPSET_DBINIT;
dbpropset[0].rgProperties = dbprop;
dbpropset[0].cProperties = sizeof(dbprop)/sizeof(dbprop[0]);
dbpropset[1].guidPropertySet = DBPROPSET_SSCE_DBINIT;
dbpropset[1].rgProperties = sscedbprop;
dbpropset[1].cProperties = sizeof(sscedbprop)/sizeof(sscedbprop[0]);
pIDBInitialize->QueryInterface(IID_IDBProperties,(void**)&pIDBProperties);
hr = pIDBProperties->SetProperties(sizeof(dbpropset)/sizeof(dbpropset[0]),dbpropset);
hr = pIDBInitialize->Initialize();
hr = pIDBInitialize->QueryInterface(IID_IDBCreateSession, (void**)&m_pIDBCreateSession);
hr = m_pIDBCreateSession->CreateSession(NULL, IID_IDBCreateCommand, (IUnknown**) &pIDBCrtCmd);
hr = pIDBCrtCmd->CreateCommand(NULL, IID_ICommandText, (IUnknown**) &pICmdText);
hr = pICmdText->SetCommandText(DBGUID_DBSQL, cmd.c_str());
hr = pICmdText->Execute(NULL, IID_NULL, NULL, NULL, NULL);
Exit:
pICmdText->Release();
pIDBProperties->Release();
pIDBInitialize->Release();
VariantClear(&dbprop[0].vValue);
VariantClear(&sscedbprop[0].vValue);
[/CODE]