What is the connection string for connecting to local db file (.mdf)
-
wrote on 12 May 2018, 06:27 last edited by
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"
-
Hi
Im not sure ODBC likes LocalDBI wonder if that have been fixed with newer versions ?
-
Hi
Im not sure ODBC likes LocalDBI wonder if that have been fixed with newer versions ?
wrote on 1 Jun 2018, 15:59 last edited by AK-47 6 Jan 2018, 16:00@mrjj said in What is the connection string for connecting to local db file (.mdf):
Hi
Im not sure ODBC likes LocalDBI 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.