CDynamicAccessor + IRowsetFastLoad (more...)



I am trying to use CDynamicAccess in conjunction with IRowsetFastLoad to
populate a SQL Server table that's created at runtime. I have code that
works if I know at compile time the structure of the table. But not
when the structure is determined at runtime.

What I see is rows being added to the table, but the contents of any
assigned field is blank.

Here's the code I'm using:

// This opens and prepares the IRowsetFastLoad.

HRESULT SqlServerBulkDataLoader::OpenDynamicRowsetFastLoad()
{
HRESULT hr;

// Enable fast load.
CComPtr<IDBProperties> properties;
CDBPropSet ps;

ps.SetGUID(DBPROPSET_SQLSERVERDATASOURCE);
ps.AddProperty(SSPROP_ENABLEFASTLOAD, true);

hr = m_DataSource.m_spInit->QueryInterface(IID_IDBProperties,
(LPVOID*) &properties);

if (FAILED(hr))
return (hr);

hr = properties->SetProperties(1, &ps);

if (FAILED(hr))
return (hr);

hr = m_Session.Open(m_DataSource);

if (FAILED(hr))
return (hr);

wchar_t tn[] = L"PerfDataLargeOleDb";
m_TableId.eKind = DBKIND_NAME;
m_TableId.uName.pwszName = new WCHAR[wcslen(tn) + sizeof
(wchar_t)];
wcscpy(m_TableId.uName.pwszName, tn);

hr = m_Session.m_spOpenRowset->OpenRowset(
NULL,
&m_TableId,
NULL,
IID_IRowsetFastLoad,
0,
NULL,
(LPUNKNOWN*) &m_RowsetFastLoad);

if (FAILED(hr))
return (hr);

hr = m_DynamicAccessor.BindColumns(m_RowsetFastLoad);

return (hr);
}

// This times and tests inserting rows using IRowsetFastLoad.

HRESULT SqlServerBulkDataLoader::DynamicRowsetFastLoadInsertData()
{
HRESULT hr;

PerfTimer t;

t.Start();

for (int iii = 0; iii < ROWS_TO_INSERT; ++iii)
{
// OK, I lied a little ... I do know that the table's first
// column is an int4.
m_DynamicAccessor.SetValue(1, iii);

hr = m_RowsetFastLoad->InsertRow(
m_DynamicAccessor.GetHAccessor(0),
m_DynamicAccessor.GetBuffer());

if (FAILED(hr))
return (hr);
}

hr = m_RowsetFastLoad->Commit(TRUE);

t.Stop();

printf("SqlServerBulkDataLoader/Dynamic\n");
printf("Rows: %d\n", ROWS_TO_INSERT);
printf("Total (s): %f\n", t.GetSeconds());
printf("Time per row (s): %f\n", t.GetSeconds() / ROWS_TO_INSERT);

if (FAILED(hr))
return (hr);

return (hr);
}

// And this closes the rowset/session.

HRESULT SqlServerBulkDataLoader::CloseDynamicRowsetFastLoad()
{
if (m_RowsetFastLoad)
{
m_DynamicAccessor.ReleaseAccessors(m_RowsetFastLoad);
m_DynamicAccessor.Close();

m_RowsetFastLoad = NULL;
}

m_Session.Close();
m_DataSource.Close();

if (NULL != m_TableId.uName.pwszName)
{
delete [] m_TableId.uName.pwszName;
m_TableId.uName.pwszName = NULL;
}

return (S_OK);
}

Any thoughts?



Chris.
.



Relevant Pages

  • IRowsetFastLoad and nvarchar (1) fields
    ... I'm using IRowsetFastLoad to bulk load a SQL Server 2000 ... definition in my DDL - I wonder if nvarchar really does ... // You will need a test database and a test table. ... HRESULT OpenDataSource() ...
    (microsoft.public.data.oledb)
  • Re: IRowsetFastLoad + Runtime Schema
    ... So I don't know at compile time the structure of the ... I need to discover this at runtime and make the row buffer appropriately. ... I haven't use IRowsetFastLoad, but my experience is that any buffer you ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (microsoft.public.data.oledb)
  • IRowsetFastLoad + Runtime Schema
    ... I want to use IRowsetFastLoad to bulk load a MSSQL Server table that's ... So I don't know at compile time the structure of the ... I need to discover this at runtime and make the row buffer appropriately. ...
    (microsoft.public.data.oledb)