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. What is the connection string for connecting to local db file (.mdf)
Forum Updated to NodeBB v4.3 + New Features

What is the connection string for connecting to local db file (.mdf)

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.5k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    AK-47
    wrote on 12 May 2018, 06:27 last edited by
    #1

    I use the following connection string to connect to database in the sqlserver instance SQLEXPRESS:

    QString connStr = "DRIVER={SQL SERVER};SERVER=.\\SQLEXPRESS;DATABASE=dbName;";
    

    But I want now to connect to SQL Server database file (.mdf) and I already installed Microsoft SQL Server 2016 LocalDB. What connection string should I use?

    I tried the following connection string:

    QString connStr = "DRIVER={SQL SERVER};SERVER=%1;AttachDbFileName=%2;"
    db.setDatabaseName(connStr.arg("(LocalDB)\\v11.0",dbFilename));
    

    And I also tried a different server:

    db.setDatabaseName(connStr.arg("(LocalDB)\\MSSQLLocalDB",dbFilename));
    

    But none of them works and throw the same error:

    "[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). QODBC3: Unable to connect"
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 12 May 2018, 09:30 last edited by
      #2

      Hi
      Im not sure ODBC likes LocalDB

      https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f21d9354-01f1-484d-b5f8-ea63e0ca76e5/odbc-driver-13-for-sql-server-localdb-problem?forum=SQLServer2016Preview

      I wonder if that have been fixed with newer versions ?

      A 1 Reply Last reply 1 Jun 2018, 15:59
      2
      • M mrjj
        12 May 2018, 09:30

        Hi
        Im not sure ODBC likes LocalDB

        https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f21d9354-01f1-484d-b5f8-ea63e0ca76e5/odbc-driver-13-for-sql-server-localdb-problem?forum=SQLServer2016Preview

        I wonder if that have been fixed with newer versions ?

        A Offline
        A Offline
        AK-47
        wrote on 1 Jun 2018, 15:59 last edited by AK-47 6 Jan 2018, 16:00
        #3

        @mrjj said in What is the connection string for connecting to local db file (.mdf):

        Hi
        Im not sure ODBC likes LocalDB

        https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f21d9354-01f1-484d-b5f8-ea63e0ca76e5/odbc-driver-13-for-sql-server-localdb-problem?forum=SQLServer2016Preview

        I wonder if that have been fixed with newer versions ?

        Thanks @mrjj for your help, I followed the link you provide and finally found a solution to my problem, I put the solution here.

        1 Reply Last reply
        1

        • Login

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