Qt-interest Archive, August 2007
How to connect with ODBC database?
Message 1 in thread
Hi all,
I compiled the sql module using -qt-sql-odbc option. But I found that I
always could not connect with my odbc database. I have tried to use
QSqlDatabase::drivers () to print drivers and it really contains odbc
driver. My code is like this:
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
QStringList list=QSqlDatabase::drivers();
for(int i=0;i<list.size();i++)
fout<<list.at(i).toAscii().data()<<endl;
db.setDatabaseName("MYDB");
if(db.open())//always return false
{
... ...
}
db.close();
Anyone could help me please?
--
[ signature omitted ]
Message 2 in thread
On Sunday 05 August 2007, zhu jiang wrote:
> Hi all,
> I compiled the sql module using -qt-sql-odbc option. But I found that I
> always could not connect with my odbc database. I have tried to use
> QSqlDatabase::drivers () to print drivers and it really contains odbc
> driver. My code is like this:
>
> QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
> QStringList list=QSqlDatabase::drivers();
> for(int i=0;i<list.size();i++)
> fout<<list.at(i).toAscii().data()<<endl;
> db.setDatabaseName("MYDB");
> if(db.open())//always return false
> {
> ... ...
> }
> db.close();
>
> Anyone could help me please?
Are you able to connect with the ODBC-Connection in another way? Make sure the
connection is working, before using it in a QT-program.
--
[ signature omitted ]
Message 3 in thread
Hi Peter,
Thanks for your answer. I have tried to use the database tool in VS2005
to connect with the ODBC database, it seems that everything is good. But
still, I could not connect with the database in my program.
2007/8/6, Peter M. Groen <pgroen@xxxxxxxx>:
>
> On Sunday 05 August 2007, zhu jiang wrote:
> > Hi all,
> > I compiled the sql module using -qt-sql-odbc option. But I found
> that I
> > always could not connect with my odbc database. I have tried to use
> > QSqlDatabase::drivers () to print drivers and it really contains odbc
> > driver. My code is like this:
> >
> > QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
> > QStringList list=QSqlDatabase::drivers();
> > for(int i=0;i<list.size();i++)
> > fout<<list.at(i).toAscii().data()<<endl;
> > db.setDatabaseName("MYDB");
> > if(db.open())//always return false
> > {
> > ... ...
> > }
> > db.close();
> >
> > Anyone could help me please?
>
> Are you able to connect with the ODBC-Connection in another way? Make sure
> the
> connection is working, before using it in a QT-program.
>
> --
> Peter M. Groen
> Open Systems Development
> Klipperwerf 12
> 2317 DZ Leiden
> Tel : +31-(0)71-5216317
> Mobile : +31-(0)6-29563390
> Email : pgroen@xxxxxxxx
> Skype: peter_m_groen
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 4 in thread
zhu jiang wrote:
> Hi all,
> I compiled the sql module using -qt-sql-odbc option. But I found
> that I always could not connect with my odbc database. I have tried to
> use QSqlDatabase::drivers () to print drivers and it really contains
> odbc driver. My code is like this:
>
> QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
> QStringList list=QSqlDatabase::drivers();
> for(int i=0;i<list.size();i++)
> fout<<list.at(i).toAscii().data()<<endl;
> db.setDatabaseName ("MYDB");
> if(db.open())//always return false
> {
> ... ...
> }
> db.close();
>
> Anyone could help me please?
>
What does db.lastError() return?
http://doc.trolltech.com/4.3/qsqldatabase.html#open
http://doc.trolltech.com/4.3/qsqldatabase.html#lastError
--
[ signature omitted ]
Message 5 in thread
Thanks, Anders. I have found the issue. The real problem is that I use
multi-byte character set instead of Unicode one in my VC++ project so that
the name of database could not be recognized. I tried to use
QString::fromLocal8Bit method to solve the problem, but it still doesn't
work.
2007/8/7, Anders Larsen <alarsen@xxxxxxxxxxxxx>:
>
> zhu jiang wrote:
>
> > Hi all,
> > I compiled the sql module using -qt-sql-odbc option. But I found
> > that I always could not connect with my odbc database. I have tried to
> > use QSqlDatabase::drivers () to print drivers and it really contains
> > odbc driver. My code is like this:
> >
> > QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
> > QStringList list=QSqlDatabase::drivers();
> > for(int i=0;i<list.size();i++)
> > fout<<list.at(i).toAscii().data()<<endl;
> > db.setDatabaseName ("MYDB");
> > if(db.open())//always return false
> > {
> > ... ...
> > }
> > db.close();
> >
> > Anyone could help me please?
> >
>
>
>
> What does db.lastError() return?
>
> http://doc.trolltech.com/4.3/qsqldatabase.html#open
> http://doc.trolltech.com/4.3/qsqldatabase.html#lastError
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 6 in thread
Things become more interesting. I changed my project into unicode one.
But still it didn't work. Then I changed the way of using
QSqlDatabase::setDatabaseName(const QString&name) method. Instead of
DSN entry name, I set the database name parameter with full
connnection string like this :
db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS
Access};DBQ=myaccessfile.mdb");
This time, everything is OK but me.
2007/8/7, Anders Larsen <alarsen@xxxxxxxxxxxxx>:
> zhu jiang wrote:
>
> > Hi all,
> > I compiled the sql module using -qt-sql-odbc option. But I found
> > that I always could not connect with my odbc database. I have tried to
> > use QSqlDatabase::drivers () to print drivers and it really contains
> > odbc driver. My code is like this:
> >
> > QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
> > QStringList list=QSqlDatabase::drivers();
> > for(int i=0;i<list.size();i++)
> > fout<<list.at(i).toAscii().data()<<endl;
> > db.setDatabaseName ("MYDB");
> > if(db.open())//always return false
> > {
> > ... ...
> > }
> > db.close();
> >
> > Anyone could help me please?
> >
>
>
>
> What does db.lastError() return?
>
> http://doc.trolltech.com/4.3/qsqldatabase.html#open
> http://doc.trolltech.com/4.3/qsqldatabase.html#lastError
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]