Exercise record for connecting to sqlserver using Python

Source: Internet
Author: User

Import pymssql

# Connect database
Conn = pymssql. Connect (host = "192.168.1.28", user = "boomink", password = "boomink", database = "boomink ")

Cur = conn. cursor ()

Print '============================================== ='

Cur.exe cute ("Exec orders_gettest1 @ value = % s", ('2017-01-01 ',))

While 1:
Print cur. fetchall ()
If 0 = cur. nextset ():
Break

Data = cur. fetchall ()

Print data

Print '============================================== ='

Export cur.exe cute ("Exec orders_gettest ")
Cur.exe cute ("Exec orders_gettest2 @ value1 = % s, @ value2 = % s", ('rule', 'yu '))

While 1:
Print cur. fetchall ()

If 0 = cur. nextset ():
Break

Data = cur. fetchall ()

Print data

Print '============================================== ='

Cur.exe cute ("Exec orders_gettracking @ begindate = % s, @ enddate = % s", ('2017-01-01 ', '2017-01-01 '))

Record = cur. fetchall ()

While 1:
Print cur. nextset ()

For R in record:
Print '============================================== ='
A = R [1]
Print 'orderid: % s' % R [0]

Print R
Print '============================================== ='

If 0 = cur. nextset ():
Break

Print "rnrow count: % d" % cur. rowcount

# Commit the connection
Conn. Commit

# Close the connection
Conn. Close

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.