How to dynamicly create a DSN by using Qt code?
I had developed a database on window platform with SQL Server as background database, now I want to restore the database in the program. As is known, we must close current connection before the operation. I know the SQL Server had a master database for default, I don't want to create this DSN by hand, Can I dynamicly create a dsn for the program? I find a example for Access database, but no example for SQL Server!
Code:
...
db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb");
if (db.open()) {
// success!
}
...
Re: How to dynamicly create a DSN by using Qt code?
You have to fill a QSqlDatabase object with appropriate data (hostname, port, login, pass, database name) using the dedicated methods.