Recently, a new project needs to use QT to connect to SQL Server on another machine, although there are similar articles on the Internet, but there are some issues that are rarely mentioned, so here's a summary:
QT Connect SQL Server can refer to this article, if it is connected to another machine, SQL Server will not have to perform the first step "open ODBC Driver"
Http://www.cnblogs.com/shaolw/p/3411285.html
Also specify that the database user name and password can use UID and pwd, that is, the original DSN parameter can be written like this:
QString DSN = QString ("driver={sql Server}; server=%1;database=%2; uid=%3; pwd=%4"). Arg (serverName). Arg (dbName). Arg (userName). Arg (password);
and "Trusted_connection=yes" also want to delete, otherwise will error.
You can refer to the following articles about how to call stored procedures:
Http://blog.chinaunix.net/uid-13830775-id-216429.html
where Qsqlquery::p repare () parameter How to write, in fact, as long as in SQL Server Management Studio First call the next stored procedure will automatically generate the calling code, the exec part of the refinement can be used directly.
It is recommended to use the Oracle format placeholder, colon, as: argname, which is much more convenient than the ODBC-formatted placeholder. In addition, if there are multiple output parameters, you can write this:
\Query.prepare ("exec pinsertpc:arg1 output,: arg2 output");
Finally, there is a need to note that the SQL The server needs to get the value of the output parameter through query.boundvalue after all result sets have been traversed, but it is still the default value for Query.bindvalue when it is not traversed, see bool Qsqlquery: Introduction of NextResult ():
Note that some databases, i.e. Microsoft SQL Server, requires non-scrollable cursors when working with multiple result set S. Some databases may execute all statements at once while others could delay the execution until the result set is ACTU Ally accessed, and some databases may has restrictions on which statements is allowed to being used in a SQL batch.
QT calls SQL Server stored procedures and obtains output parameters