T
temlehdrol
Guest
ok I'm just trying to execute a query into a recordset, nothing out of the ordinary here.
C# Code:
while (reader.Read())
{
int i1 = reader.GetInt32(0),
i2 = reader.GetInt16(1),
i3 = 0;
if (!reader.IsDBNull(2))
{
i3 = reader.GetInt32(2);
bolNullFound = false;
//str3 = Convert.ToString(i3);
}
else
bolNullFound = true;
++counter1; // Console.WriteLine(reader.GetInt16(1));
//Start of TEST
DataRow row = ds2.Tables["T1Test"].NewRow();
row["EventID"] = i1;
row["EventCode"] = i2;
if (bolNullFound == false)
{
row["DebtID"] = i3;
}
else
row["DebtID"].Equals(DBNull.Value);
ds2.Tables["T1Test"].Rows.Add(row);
}
in C++ we have:
CDatabase cd;
CRecordset sourcers(&cd);
CString DSNString = _T("DSN=database;UID=sa;PWD=password;"),
SQLString = _T("SELECT EventID, EventCode, Debtid FROM Events WHERE Eventcode IN (10, 16)");
try
{
cd.OpenEx(DSNString, NULL );
}
catch(CDBException *e )
{
AfxMessageBox(_T("Didn't open ODBC database.\n") + e->m_strError);
throw;
}
try
{
sourcers.Open( CRecordset::snapshot , SQLString );
}
catch(CDBException *e )
{
AfxMessageBox(_T("failed opening ODBC CRecordset ") + e->m_strError);
throw;
}
int fieldcount = sourcers.GetODBCFieldCount( ), i, rec;
CDBVariant varValue;
//CString tstring;
long int tc = 0;
printf("Starting...\n");
CTime starttime = CTime::GetCurrentTime();
if ( !sourcers.IsEOF() )
sourcers.MoveFirst();
while ( !sourcers.IsEOF())
{
for ( i = 0; i < fieldcount; ++ i ) // do nothing other than load field into tstring
sourcers.GetFieldValue(i, varValue);
++tc;
// } // end for rec
try
{
sourcers.MoveNext();
}
catch( CDBException *e )
{
AfxMessageBox( _T("MoveNext Failed: ") + e->m_strError);
throw;
}
} // end while
The C# takes around 1 second to complete for 85,000 records and the C++ is taking around 90 seconds for the same 85,000 records this is all being done over the network. Run locally it's about 10 seconds for the C++ app.
Any ideas as to why this is so much slower? This is with Windows 2008 Server, and SQL Server 2000. Running this on our other network with Windows 2000 Server and SQL Server 2000 it runs in 12 - 15 seconds (C++ tested only not C#)
Continue reading...
C# Code:
while (reader.Read())
{
int i1 = reader.GetInt32(0),
i2 = reader.GetInt16(1),
i3 = 0;
if (!reader.IsDBNull(2))
{
i3 = reader.GetInt32(2);
bolNullFound = false;
//str3 = Convert.ToString(i3);
}
else
bolNullFound = true;
++counter1; // Console.WriteLine(reader.GetInt16(1));
//Start of TEST
DataRow row = ds2.Tables["T1Test"].NewRow();
row["EventID"] = i1;
row["EventCode"] = i2;
if (bolNullFound == false)
{
row["DebtID"] = i3;
}
else
row["DebtID"].Equals(DBNull.Value);
ds2.Tables["T1Test"].Rows.Add(row);
}
in C++ we have:
CDatabase cd;
CRecordset sourcers(&cd);
CString DSNString = _T("DSN=database;UID=sa;PWD=password;"),
SQLString = _T("SELECT EventID, EventCode, Debtid FROM Events WHERE Eventcode IN (10, 16)");
try
{
cd.OpenEx(DSNString, NULL );
}
catch(CDBException *e )
{
AfxMessageBox(_T("Didn't open ODBC database.\n") + e->m_strError);
throw;
}
try
{
sourcers.Open( CRecordset::snapshot , SQLString );
}
catch(CDBException *e )
{
AfxMessageBox(_T("failed opening ODBC CRecordset ") + e->m_strError);
throw;
}
int fieldcount = sourcers.GetODBCFieldCount( ), i, rec;
CDBVariant varValue;
//CString tstring;
long int tc = 0;
printf("Starting...\n");
CTime starttime = CTime::GetCurrentTime();
if ( !sourcers.IsEOF() )
sourcers.MoveFirst();
while ( !sourcers.IsEOF())
{
for ( i = 0; i < fieldcount; ++ i ) // do nothing other than load field into tstring
sourcers.GetFieldValue(i, varValue);
++tc;
// } // end for rec
try
{
sourcers.MoveNext();
}
catch( CDBException *e )
{
AfxMessageBox( _T("MoveNext Failed: ") + e->m_strError);
throw;
}
} // end while
The C# takes around 1 second to complete for 85,000 records and the C++ is taking around 90 seconds for the same 85,000 records this is all being done over the network. Run locally it's about 10 seconds for the C++ app.
Any ideas as to why this is so much slower? This is with Windows 2008 Server, and SQL Server 2000. Running this on our other network with Windows 2000 Server and SQL Server 2000 it runs in 12 - 15 seconds (C++ tested only not C#)
Continue reading...