neilwey

C++ error creating raster dataset

Discussion created by neilwey on Jul 4, 2013
I am porting a plugin from 9.2 to 10.1 and am getting an error creating a raster dataset

I have written a test harness to reproduce the problem which is as follows:
------------------------------------------------------------------------------------------
HRESULT ConnectToWorkspace(IWorkspacePtr &ipWork)
{
CComBSTR username = "username";
CComBSTR password = "password";
CComBSTR server = "servername";
CComBSTR instance = "5151";
CComBSTR database = "";
CComBSTR szVersion = "SDE.DEFAULT";

// Set connection properties
IPropertySetPtr ipPropertySet;
ipPropertySet.CreateInstance(CLSID_PropertySet);

ipPropertySet->SetProperty(CComBSTR(L"SERVER"), CComVariant(server) );
ipPropertySet->SetProperty(CComBSTR(L"INSTANCE"), CComVariant(instance) );
ipPropertySet->SetProperty(CComBSTR(L"DATABASE"), CComVariant(database) );
ipPropertySet->SetProperty(CComBSTR(L"USER"), CComVariant(username) );
ipPropertySet->SetProperty(CComBSTR(L"PASSWORD"), CComVariant(password) );
ipPropertySet->SetProperty(CComBSTR(L"VERSION"), CComVariant(szVersion));

// Create the workspace
IWorkspaceFactoryPtr ipWorkspaceFactory;
ipWorkspaceFactory.CreateInstance(CLSID_SdeWorkspaceFactory);
HRESULT hr = ipWorkspaceFactory->Open(ipPropertySet, NULL, &ipWork);

return hr;
}

HRESULT CreateRasterDataset (IWorkspacePtr &ipWork, _bstr_t bstrRasterDatasetName)
{

IRasterWorkspaceExPtr ipRasterWorkspaceEx(ipWork);

// Raster dataset values
int iNumOfBands(1);
rstPixelType pixelType(PT_CHAR);
_bstr_t bstrKeyword(L""); // No keywords
IRasterDatasetPtr ipRasterDataset;

HRESULT hr = ipRasterWorkspaceEx->CreateRasterDataset(bstrRasterDatasetName, iNumOfBands, pixelType,
NULL, bstrKeyword, NULL,
NULL, &ipRasterDataset);

return hr;
}

int _tmain(int argc, _TCHAR* argv[])
{
Initialise();

_bstr_t bstrRasterDatasetName(argv[1]);

IWorkspacePtr ipWorkspace;

HRESULT hr = ConnectToWorkspace(ipWorkspace); 
if(!SUCCEEDED(hr))
return hr;

hr = CreateRasterDataset(ipWorkspace, bstrRasterDatasetName);

if(SUCCEEDED(hr))
{
std::cout << "SUCCESS!!" << std::endl;
return 0;
}
else if (hr == FDO_E_SE_FAILURE)
std::cout << "FDO_E_SE_FAILURE" << std::endl;
else if (hr == FDO_E_SE_TABLE_EXISTS)
std::cout << "FDO_E_SE_TABLE_EXISTS " << bstrRasterDatasetName << std::endl;
else if (hr == FDO_E_ITEM_WITH_PATH_EXISTS)
std::cout << "FDO_E_ITEM_WITH_PATH_EXISTS " << bstrRasterDatasetName << std::endl;
else if (hr == SDE_E_SE_INVALID_IDENTIFIER)
std::cout << "SDE_E_SE_INVALID_IDENTIFIER " << bstrRasterDatasetName << std::endl;
else 
std::cout << "Error: " << hr << std::endl;

return hr;
}

-----------------------------------------------------------------------------------------
It just keeps on returning FDO_E_SE_FAILURE
It is creating a table because if I call it twice with the same dataset name I get FDO_E_SE_TABLE_EXISTS
Any help would be gratefully appreciated - I have been banging my head against this one for a week

Outcomes