QT calls SQL Server stored procedures and obtains output parameters

Source: Internet
Author: User
Tags dsn microsoft sql server management studio sql server management sql server management studio



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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.