MS SQLServer

Forum for posting problems using QxOrm library

MS SQLServer

Postby marat » Wed Oct 17, 2012 9:55 pm

I have been using MySQL up till now, but how would I connect to SQLServer? Should I use
qx::QxSqlDatabase::getSingleton()->setDriverName("QSQLITE"); ?

Or is there a way to use ODBC ?
marat
 
Posts: 15
Joined: Tue Jul 17, 2012 8:23 pm

Re: MS SQLServer

Postby qxorm » Thu Oct 18, 2012 7:44 am

Hi,

how would I connect to SQLServer? ...
... Or is there a way to use ODBC ?

Yes, to connect to Microsoft SqlServer, you have to use the ODBC plugin (http://www.qxorm.com/qxorm_en/faq.html#faq_40).
So, it is :
Code: Select all
qx::QxSqlDatabase::getSingleton()->setDriverName("QODBC");


Another thing you have to do => specify what database you are using (because ODBC doesn't say with which database you are working).
Here is the code you have to write (just after your setDriverName() call) :
Code: Select all
qx::dao::detail::QxSqlGenerator_MSSQLServer_ptr pSqlGenerator = qx::dao::detail::QxSqlGenerator_MSSQLServer_ptr(new qx::dao::detail::QxSqlGenerator_MSSQLServer());
qx::QxSqlDatabase::getSingleton()->setSqlGenerator(pSqlGenerator);
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: MS SQLServer

Postby marat » Thu Oct 18, 2012 2:40 pm

Ok, thanks.

When I tried using qx::QxSqlDatabase::getSingleton()->setDriverName("QODBC");

QSqlDatabase: QODBC driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL3 QMYSQL

So I went ahead and downloaded ODBC drivers (for linux) from http://www.microsoft.com/en-us/download ... x?id=28160
I followed the instructions and installed. There is a libsqlncli-11.0.so.1790.0 shared library.

Do I need to rebuild QxOrm? What else needs to be done?
marat
 
Posts: 15
Joined: Tue Jul 17, 2012 8:23 pm

Re: MS SQLServer

Postby qxorm » Thu Oct 18, 2012 8:45 pm

QSqlDatabase: QODBC driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL3 QMYSQL
...
Do I need to rebuild QxOrm? What else needs to be done?

That means that you don't have the Qt ODBC plugin.
So, you have to build it or download it.
You can find more information about Qt Sql plugins on Qt website : http://doc.qt.digia.com/4.7-snapshot/sql-driver.html
I think you could easily find a tutorial on the web to explain how to compile a Qt Sql plugin (in your case ODBC plugin)...

Edit : I found those command line (but not tested) :
Code: Select all
cd $QTDIR/src/plugins/sqldrivers/odbc
qmake "INCLUDEPATH+=/usr/local/unixODBC/include" "LIBS+=-L/usr/local/unixODBC/lib -lodbc"
make
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: MS SQLServer

Postby marat » Fri Oct 19, 2012 2:47 pm

Thanks.

So I have been using the qt4 distribution on my redhat with the latest QxOrm.

As expected the /usr/lib64/qt4/plugins/sqldrivers/ show only libqsqlite.so* libqsqlmysql.so*.

I guess that means I need to download the Qt4 source code and build the libqodbc.so plugin - correct ?

Update:
I have downloaded qt and built the sql driver plugin libqsqlodbc.so and installed/copied into the /usr/lib64/qt4/plugins/sqlddrivers/ .
Now what should be done so that the odbc qt plugin is loaded? Its still not picking it up.
marat
 
Posts: 15
Joined: Tue Jul 17, 2012 8:23 pm

Re: MS SQLServer

Postby qxorm » Mon Oct 22, 2012 8:48 am

I have downloaded qt and built the sql driver plugin libqsqlodbc.so and installed/copied into the /usr/lib64/qt4/plugins/sqlddrivers/.
Now what should be done so that the odbc qt plugin is loaded? Its still not picking it up.

Do you have the same error message ? (QSqlDatabase: QODBC driver not loaded - QSqlDatabase: available drivers: QSQLITE QMYSQL3 QMYSQL).
Do you read the Qt documentation : http://doc.qt.digia.com/4.7-snapshot/sq ... html#qodbc ?

Sorry, but I'm not an expert about adding a Qt Sql plugin : it's not a QxOrm problem, but a Qt problem !
I think you should have more answers if you ask directly on a Qt forum how to add the QODBC plugin...
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: MS SQLServer

Postby marat » Mon Oct 22, 2012 3:08 pm

Ok, I installed the linux qt-odbc package (instead of having to build the plugin).

Now, it looks more like a programmatical issue -

[QxOrm] qx::QxSqlDatabase : 'unable to open connection to database'
Error number '0' : [unixODBC][Driver Manager]Data source name not found, and no default driver specified QODBC3: Unable to connect
QODBC3: Unable to connect
[unixODBC][Driver Manager]Data source name not found, and no default driver specified

Here is the code:
Code: Select all
qx::QxSqlDatabase::getSingleton()->setDriverName("QODBC");
qx::dao::detail::QxSqlGenerator_MSSQLServer_ptr pSqlGenerator =
       qx::dao::detail::QxSqlGenerator_MSSQLServer_ptr(new qx::dao::detail::QxSqlGenerator_MSSQLServer());
qx::QxSqlDatabase::getSingleton()->setSqlGenerator(pSqlGenerator);
qx::QxSqlDatabase::getSingleton()->setDatabaseName("dbTest");   
qx::QxSqlDatabase::getSingleton()->setHostName(ip);
qx::QxSqlDatabase::getSingleton()->setUserName(user);
qx::QxSqlDatabase::getSingleton()->setPassword(pw);


How do I specify the data source name? I may also be missing something with the above (sqlGenerator) ?

Thanks.

EDIT
If I change the setDatabaseName() to use the DSN entry in odbc.ini like so:
Code: Select all
qx::QxSqlDatabase::getSingleton()->setDatabaseName("DSN_TEST");   


Output:
[QxOrm] qx::QxSqlDatabase : 'unable to open connection to database'
Error number '10022' : [unixODBC][Microsoft][SQL Server Native Client 11.0]Login timeout expired [unixODBC][Microsoft][SQL Server Native Client 11.0]A network-related or
QODBC3: Unable to connect
[unixODBC][Microsoft][SQL Server Native Client 11.0]Login timeout expired [unixODBC][Microsoft][SQL Server Native Client 11.0]A network-related or
0

My odbc.ini
[DSN_TEST]
Driver=SQL Server Native Client 11.0
Server=172.19.1.xxx
Database=dbTest


My odbcinst.ini
[SQL Server Native Client 11.0]
Description=Microsoft SQL Server ODBC Driver V1.0 for Linux
Driver=/opt/microsoft/sqlncli/lib64/libsqlncli-11.0.so.1790.0
Threading=1
UsageCount=1


Any ideas?
marat
 
Posts: 15
Joined: Tue Jul 17, 2012 8:23 pm

Re: MS SQLServer

Postby qxorm » Tue Oct 23, 2012 10:43 am

Now, it looks more like a programmatical issue

Nope, sorry, this is an ODBC setting problem ;)

I may also be missing something with the above (sqlGenerator) ?

No, I think it's ok about your sql generator.

Error number '10022' : [unixODBC][Microsoft][SQL Server Native Client 11.0]Login timeout expired [unixODBC][Microsoft][SQL Server Native Client 11.0]A network-related or QODBC3: Unable to connect
[unixODBC][Microsoft][SQL Server Native Client 11.0]Login timeout expired [unixODBC][Microsoft][SQL Server Native Client 11.0]A network-related or 0

It seems to try to connect to your SqlServer database.
You should ask in a Qt forum... Because I don't know what is wrong with your setting ;)
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: MS SQLServer

Postby marat » Tue Oct 23, 2012 1:50 pm

Yes, it was an OBDC configuration. Thank you.
marat
 
Posts: 15
Joined: Tue Jul 17, 2012 8:23 pm

Re: MS SQLServer

Postby qxorm » Wed Oct 24, 2012 11:07 am

Yes, it was an OBDC configuration. Thank you.

Great ! ;)
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 7 guests