|
|
Question : Using ADO with SQL 7.0 - performance issue
|
|
Hello friends, I am writing an database application in MFC for which I am using SQL Server 7.0. My app has to fetch records from a particular table and print them to a file. I am using ADO for this and my code goes like
#import #undef EOF
HRESULT hr = S_OK; ADODB::_RecordsetPtr Rs1 = NULL; _bstr_t Connect("DSN=isro9mdatasource;UID=sa;PWD=;"); _bstr_t Source ("SELECT * FROM ISR_TC_TEMP_STATUS where Ch_no = 'TC001'");
hr = Rs1.CreateInstance( __uuidof( ADODB::Recordset ) ); CTime t = CTime::GetCurrentTime(); Rs1->Open( Source,Connect,ADODB::adOpenStatic, ADODB::adLockReadOnly,-1); TRACE("Record count = %ld\n",Rs1->RecordCount);
CTimeSpan ts = CTime::GetCurrentTime() - t; TRACE("Total Seconds = %ld\n", ts.GetTotalSeconds());
t = CTime::GetCurrentTime(); for(int i = 0; i < Rs1->RecordCount; i++) { Print( (char*) ((_bstr_t) Rs1->Fields->GetItem(long(0))->Value), (char*) ((_bstr_t) Rs1->Fields->GetItem(long(1))->Value), (char*) ((_bstr_t) Rs1->Fields->GetItem(long(2))->Value), (char*) ((_bstr_t) Rs1->Fields->GetItem(long(3))->Value)); Rs1->MoveNext(); } ts = CTime::GetCurrentTime() - t; TRACE("Total Seconds = %ld\n", ts.GetTotalSeconds());
Rs1->Close(); Rs1 = NULL;
The problem I am facing is that my query results in fetching around 20,000 records from the database (there are actually 14,00,000 recs totally) which is taking a hell of a lot of time. The actual query takes around 6-8 secs but the part where I scroll thro each record and print it totally takes 180 secs for 20,000 recs (3 mins). The performance doesnt change even if the printing part is removed. I have noticed that in SQL Query analyzer the same query is executed and the results are displayed in about 2 -3 secs. What is the best alternative or solution to this. Please help.
Adarsh
|
Answer : Using ADO with SQL 7.0 - performance issue
|
|
Hi bhat, Well, I would suggest you to go for paging concept. That way you can take at a time a few records. When u surf around google or any search engine this is that same thing happening. And for connection time out
Public Function Insert(ByVal x As Variant) On Error GoTo Errobj: Set cn = New ADODB.Connection cn.Open "Provider=SQLOLEDB;data Source=sachipc;" _ & "Initial Catalog=blob;User Id=sa;Password="
cn.CommandTimeout = 0 Set rs = New ADODB.Recordset rs.Open "Select * from TestingIMG", cn, adOpenKeyset, adLockOptimistic
rs.AddNew Set mstream = New ADODB.Stream mstream.Type = adTypeBinary mstream.Open mstream.LoadFromFile "c:\setup.zip" 'mstream.Write (VarX) rs.Fields("ID") = 1111 rs.Fields("Img").Value = mstream.Read rs.Update rs.Close cn.Close
Errobj: Debug.Print Err.Description & Err.Number
End Function
This is for command time out. Same way you have to do it for connection.
hope u got it..Let me know the updates..
Cheers!! Sachi
|
|
|
|
|