Clear database error logs using python

Source: Internet
Author: User
# Connection # connect to the database connpyodbc. connect (DRIVER {SQLServer}; SERVER192.168.1.43; DATABASEmaster; UIDsa; PWDpasswd123 !) # Getting curs

# Coding = gbk from encodings import gbk import re import sys import OS import pyodbc import traceback import decimal # connect to database conn = pyodbc. connect (DRIVER = {SQL Server}; SERVER = 192.168.1.43; DATABASE = master; UID = sa; PWD = passwd123 !) # Getting curs

# Coding = gbk
From encodings import gbk
Import re
Import sys
Import OS
Import pyodbc
Import traceback
Import decimal

# Connecting to a database
Conn = pyodbc. connect ('driver = {SQL Server}; SERVER = 192.168.1.43; DATABASE = master; UID = sa; PWD = passwd123! ')

# Obtain the cursor object for operations
Cursor = conn. cursor ()

# Clearing error logs
# Query = "select username, userid from dbo. tbluser where username = '% S'" % (uname)
Query = "EXEC sys. sp_cycle_errorlog"
Cursor.exe cute (query)
Conn. commit

Data = cursor. nextset ()

While not data:
Print ('43 error logs cleared! ')
Break

# Clearing proxy logs
# Query = "select username, userid from dbo. tbluser where username = '% S'" % (uname)
Query1 = "EXEC msdb. dbo. sp_cycle_agent_errorlog"
Cursor.exe cute (query1)
Conn. commit

Data1 = cursor. nextset ()

While not data1:
Print ('43 proxy logs cleared! ')
Break
# Close the connection and release resources

Cursor. close ()
Conn. close ()

Com3 = 'pause'
OS. system (com3)

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.