Results 1 to 5 of 5

Thread: Connect To Database

  1. #1
    Join Date
    May 2015
    Posts
    42
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    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
    5,243
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    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
    Join Date
    May 2015
    Posts
    42
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    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
    5,243
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    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.

  5. #5
    Join Date
    May 2015
    Posts
    42
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Connect To Database

    Hey d_stranz,
    sorry to come back to you too late. Was out of the office. This last post of you gave me a lot of homework. Step by step I begin now to understand databases. Hopefully I'll start liking it one day. The more I dig, the more I suffer ;-)
    My root field of programming was data-acquisition and processing of vid/aud-data. This, now, is a good extension of my skills.
    Thanks for that great support. Sure I'll return with new silly problems :-) Soon.

    Lars

Similar Threads

  1. How to Connect to MySQL database
    By johnL in forum Newbie
    Replies: 12
    Last Post: 16th May 2015, 17:43
  2. Cannot connect to mysql database
    By phapha in forum Newbie
    Replies: 3
    Last Post: 27th October 2011, 15:58
  3. Connect A Database With code
    By Fk_king in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 10th September 2011, 19:02
  4. Connect to database
    By seink in forum Newbie
    Replies: 12
    Last Post: 26th April 2011, 19:43
  5. Questions about connect to remote database
    By stmk in forum Qt Programming
    Replies: 3
    Last Post: 11th November 2010, 11: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.