PDA

View Full Version : fast read write mssql information from remot server



hamidarr
15th July 2011, 09:28
hi everybody i have a vps server with windows 2003 server and mssql 2008 i connect with port 1433 to mssql in my qt application and read and write information on it but it slow.
how can i read and write information fast from mssql on vps server?

SixDegrees
15th July 2011, 11:00
Slow compared to what? If you make the identical query through the SQL command line, does it run faster? If you haven't tried this, be sure to try Qt then SQL CLI a few times in succession to reduce various caching effects. It would also be helpful to run the same query on the server itself to narrow down which of the components - database, connection, client - is taking the most time.

Of course, if the Qt and remote CLI queries take the same amount of time, the problem lies on the DB side of the fence. It may also be that the query itself is inherently slow - returns a large result or involves complex data manipulations to construct.

hamidarr
17th July 2011, 11:06
compare with local database.my program work with mssql2008 and need to write large information to database and read.sql command line and qt have same speed i want a solution to increase my speed.can anybody help me

SixDegrees
17th July 2011, 11:33
Since the speed is the same for both direct command line access and Qt access, this isn't a Qt question. You'd be much better off consulting a mssql group and asking them how best to optimize DB access. Note that reading/writing a large amount of information will take a relatively large amount of time, no matter what.

hamidarr
22nd July 2011, 22:02
i found my problem when i execute a qyery and show the result with qDebug like this it is fast and good speed

QSqlQuery query(QSqlDatabase::database("con"));
QSqlRecord rec;
query.setForwardOnly(true);
query.exec(QString("{CALL AddCourse(%1,%2,%3)}").arg(majoridd).arg(degreeid).arg(termid));
if(!query.isActive())
{
qDebug()<<"EROOORR QUERY";

}
else
{
while(query.next())
{
rec = query.record();
qDebug()<<"0:"<<rec.value(0)<<"1:"<<rec.value(1)<<"2:"<<rec.value(2)
<<"3:"<<rec.value(3)<<"4:"<<rec.value(4)<<"5:"<<rec.value(5)
<<"6:"<<rec.value(6)<<"7:"<<rec.value(7);
}
}
when i use QTableWidget to show information like this it too slow


addtableWidget->setItemDelegate(new CheckDelegate);
QTableWidgetItem *item = 0;
//QSqlDatabase::database("con").open();
QSqlQuery query(QSqlDatabase::database("con"));
QSqlRecord rec;
query.setForwardOnly(true);
query.exec(QString("{CALL AddCourse(%1,%2,%3)}").arg(majoridd).arg(degreeid).arg(termid));
if(!query.isActive())
{
QMessageBox::warning(this, "خطا",
"لطفا با پشتيباني تماس بگيريد");

}
else
{
int row = 1;
addtableWidget->setRowCount(row);

addlist.clear();

int i = 0;
while (query.next())
{
// rec = query.record();
addtableWidget->setItem(i,0,item = new QTableWidgetItem);
item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsUserCheckable );
item->setCheckState( Qt::Unchecked);
rec = query.record();
addlist.insert(i,rec.value(0).toInt());

for(int j = 1 ; j<=8 ; j++)
{

QTableWidgetItem *item1 = new QTableWidgetItem(rec.value(j).toString());
addtableWidget->setItem(i,j,item1);

item1->setFlags(Qt::ItemIsEnabled);

}

addtableWidget->setRowCount(row+=1);
i++;

}

addtableWidget->setRowCount(row-=1);





addtableWidget->resizeColumnsToContents();



}

}

QSqlDatabase::database("con").close();

}

i guese my problem is QTableWidget can anyone help me?