March 16, 2012

Suths Suths
Lab Rat
13 posts

QODBC plugin compile

 

Hi everyone,

Just wondering if anyone had any guidance for how to get QODBC to work inside visual studio 2008? So far I have downloaded Qt libraries 4.8.0 for Windows (VS 2008, 273 MB), and followed the online instructions for compiling the plugin, navigating to C:\Qt\4.8.0\src\plugins\sqldrivers\odbc, then running qmake odbc.pro, then nmake, however when i try to open a connection to the server I get
‘Error “[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect” ‘

Does any one have any ideas my code is as follows:

  1.  QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "MyDatabase");
  2.  db.setHostName("LOCALHOST\\SQLEXPRESS");
  3.   db.setDatabaseName("test");
  4.   db.setUserName("...");
  5.   db.setPassword("...");
  6.  
  7.   if(db.open())
  8.   {
  9.    qDebug() << "Opened";
  10.    db.close();
  11.   }
  12.  
  13.   else
  14.    qDebug() << "Error" << db.lastError().text();

3 replies

March 16, 2012

Scylla Scylla
Lab Rat
238 posts

Take a look here [stackoverflow.com].

Hope this helps.

March 16, 2012

francomartins francomartins
Hobby Entomologist
61 posts

Example of SQL Server Conection :

  1. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "MyDatabase");
  2.  
  3. db.setDatabaseName("DRIVER={SQL Server};Server="+ipserver+";Database="+database+";Uid="+LoginName+";Port=1433;Pwd="+Pass+";WSID=");
  4.  
  5. if(db.open())
  6.   {
  7.    qDebug() << "Opened";
  8.    db.close();
  9.   }
  10.   else
  11.    qDebug() << "Error" << *db*.lastError().text();

the WSID =. “is used to hide the client machine to the database server log

[EDIT: code formatting, please use @-tags, Volker]

April 3, 2012

Suths Suths
Lab Rat
13 posts

Thanks very much guys using your two responses i was able to fix my problem.

 
  ‹‹ ’QTableView’ with per column ’minimumSectionSize’      Question about debug and release mode. ››

You must log in to post a reply. Not a member yet? Register here!