Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt QSql: cannot create a new MDB-File per ODBC

Qt QSql: cannot create a new MDB-File per ODBC

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 242 Views
  • 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.
  • P Offline
    P Offline
    PMime
    wrote on last edited by
    #1

    I am using the following code to create a NEW MS Access file using the SQL API from Qt.

    QString strDatabaseName;
    if (strExt == ".DB")
    {
        oQtDatabase = QSqlDatabase::addDatabase(_TN("QSQLITE"), _TN("Redline_DB"));
        strDatabaseName = strDatei;
    }
    if (strExt == ".MDB" || strExt == ".ACCDB")
    {
        oQtDatabase = QSqlDatabase::addDatabase(_TN("QODBC"), _TN("Redline_MDB"));
        strDatabaseName = _TN("Driver={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DSN='';DBQ=") + QString::fromLatin1(strDatei);
    }
    
    oQtDatabase.setDatabaseName(strDatabaseName);
    
    if (!oQtDatabase.open())
        throw oQtDatabase.lastError();
    

    The part for SQLite is succesful in creating a .DB File. Unfortunately QODBC throws an error:

    [Microsoft][ODBC-Treiber für Microsoft Access] Datei '(unbekannt)' nicht gefunden. QODBC3: Unable to connect
    

    Which means: ODBC-driver for Microsoft Access, File 'unkown' not found

    I have to mention that the connection string works well with an existing Access file.

    Thanks in advance for your help.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      In general, you cannot connect to a database that does not already exist: as a file in the case of Access, or a service for MySql/Oracle etc. Sqlite is unusual in that it will create the file referenced if it does not exist (that can also fail).

      You can programmatically create an Access database by automating Access (ActiveQt) and probably a bunch of other ways, including copying an "empty" template.

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved