Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QSQL: Data source name too long QODBC3: Unable to connect

    General and Desktop
    2
    2
    3814
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      Laserbeak43 last edited by

      Hello,
      I'm very new to database programming and seem to have a problem getting my db to connect. I'm not even sure if my project can even find it. I was wondering if you could help me. I get the error:

      bq. [Microsoft][ODBC Driver Manager]Data source name too long QODBC3: Unable to connect

      My db file name is "SpellingWords.sdf" I kind of followed along with a tutorial but was still pretty confused on how i make the database info match mine. I am using SQL Server 2008 Compact Edition.

      @
      WordEditor::WordEditor(QWidget *parent) :
      QDialog(parent),
      ui(new Ui::WordEditor)
      {
      ui->setupUi(this);
      QString servername = "LocalHost\SQLEXPRESS";
      QString dbname = "SpellingWords";
      QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
      db.setConnectOptions();
      //QString dsn = QString("DRIVER=(SQL Native Client);SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").arg(servername).arg(dbname);
      QString dsn = QString("..\..\SpellingBee\SpellingWords.sdf");
      db.setDatabaseName(dsn);

      if(db.open())
      {
        QMessageBox mBox;
        mBox.setText("Open!");
        mBox.exec();
      

      }
      else
      {
      QMessageBox mBox;
      mBox.setText(db.lastError().text());
      mBox.exec();
      }
      }
      @

      1 Reply Last reply Reply Quote 0
      • A
        Alek Śmierciak last edited by

        Why the backslashes in the dsn QString? The name is hard-coded anyway, you're not performing any search for a file this way. Leave it as just "SpellingWords.sdf", which, according to "QSqlDatabase dcoumentation":http://qt-project.org/doc/qt-5.0/qtsql/qsqldatabase.html#setDatabaseName, is one of the recommended names for an ODBC-connected database:

        bq. For the QODBC driver, the name can either be a DSN, a DSN filename (in which case the file must have a .dsn extension), or a connection string.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post