+ Reply to Thread
Results 1 to 4 of 4

Thread: Connect To Database

  1. #1

    Default Connect To Database

    Hi Everybody,

    I run a program that connects to a database like this:

    Qt Code:
    1. QSqlDatabase dB = QSqlDatabase::addDatabase("QODBC");
    2. dB.setHostName("localhost");
    3. dB.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DSN='';DBQ=C:/Program Files (x86)/myFolder/myAccesApp.mdb;");
    To copy to clipboard, switch view to plain text mode 

    This obviously refers to an *mdb-file on localhost. Now: I'd like to connect directly to the database and not go through the mdb-file. Here's a snippet off the regEdit:

    Qt Code:
    1. [HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\SomeName]
    2. "Driver"="%systemroot%\\System32\\SQLSRV32.DLL"
    3. "Description"="SomeDescription"
    4. "Server"="MYHOSTNAME"
    5. "LastUser"="me"
    6. "Trusted_Connection"="Yes"
    7. "Database"="NameOfDatabase"
    To copy to clipboard, switch view to plain text mode 


    How (if) would I form a sufficient string for the setDatabaseName() - methode?
    Or am I completely wrong and without *mdb there is no way?

    My basic problem is, that if I run more than one instance of the program (all looking at the same database of course), the database goes nuts and writes completely irrelevant crap into the tables using the sql - "update" - command.
    Perhaps there is another major blindspot on my side?

    Every help highly appreciated.

    Regards, Lars

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,609
    Thanks
    210
    Thanked 554 Times in 544 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Connect To Database

    the database goes nuts and writes completely irrelevant crap into the tables using the sql - "update" - command.
    Perhaps there is another major blindspot on my side?
    Seems pretty obvious that the way you are using the MDB driver doesn't support multiple concurrent write access if you end up with a corrupted database when you try to use it that way.

    Here is a good Stackoverflow discussion of MDB concurrency.

    Now: I'd like to connect directly to the database and not go through the mdb-file.
    I am not at all sure what you mean by this. The mdb file -is- the database.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3

    Default Re: Connect To Database

    Hey d_stranz, nice to hearing from you again.

    Yeah, this is what I think too. That's why my approach is to find out how this particular database really works. What is puzzling me is the fact, that the mdb-file itself is just of the size 7MB. Impossible to be a database. The file-type-description names it a windows-access-application.

    Now:
    If you skip the first part of my question and you only see the snippet of the ini-file posted earlier, you can come to the conclusion, that the mdb-file is just a vehicle to adress the data on
    Qt Code:
    1. HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\SomeName]
    To copy to clipboard, switch view to plain text mode 
    isn't it?

    The company runs this particular *.mdb on a lot of computers and they pretty much do a good job working on the same datasource/(database?) simultaniously.

    As I explained much earlier, I'm not an expert on database-stuff. So, here's my question again, but hopefully more precise: If you wouldn't know about some mdb-file, could you connect to any database only from the information given by the snippet, shown here again?

    Qt Code:
    1. HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\SomeName]
    2. "Driver"="%systemroot%\\System32\\SQLSRV32.DLL"
    3. "Description"="SomeDescription"
    4. "Server"="MYHOSTNAME"
    5. "LastUser"="me"
    6. "Trusted_Connection"="Yes"
    7. "Database"="NameOfDatabase"
    To copy to clipboard, switch view to plain text mode 

    regards, Lars

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,609
    Thanks
    210
    Thanked 554 Times in 544 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Connect To Database

    If you wouldn't know about some mdb-file, could you connect to any database only from the information given by the snippet
    AFAIK, this registry entry simply tells the ODBC driver which specific DB access DLL to load when someone requests to open "SomeName" using ODBC. In essence, this is what your QSqlDatabase calls are doing - you've told it to use ODBC, and you've told it the name of the database, so the ODBC driver is going to out to the registry, look up this information, and open the database if it can.

    Any program that uses the Microsoft ODBC driver will go through the same process, whether through Qt's layer, .NET, or some other database access layer. So unless you have code that will read MDB files directly, without going through an ODBC driver layer, you will be following this path too.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

+ Reply to Thread

Similar Threads

  1. How to Connect to MySQL database
    By johnL in forum Newbie
    Replies: 12
    Last Post: 16th May 2015, 16:43
  2. Cannot connect to mysql database
    By phapha in forum Newbie
    Replies: 3
    Last Post: 27th October 2011, 14:58
  3. Connect A Database With code
    By Fk_king in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 10th September 2011, 18:02
  4. Connect to database
    By seink in forum Newbie
    Replies: 12
    Last Post: 26th April 2011, 18:43
  5. Questions about connect to remote database
    By stmk in forum Qt Programming
    Replies: 3
    Last Post: 11th November 2010, 10:02

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts