Python remotely clears the SQL Server database servers log for reference:
# CODING=GBK
From encodings Import GBK
Import re
Import Sys
Import OS
Import Pyodbc
Import Traceback
Import Decimal
#连接数据库
conn = Pyodbc.connect (' Driver={sql Server}; Server=192.168.1.43;database=master; Uid=sa; Pwd=passwd123123 ')
# get the cursor object to manipulate
cursor = Conn.cursor ()
#清除错误日志
#query = "Select Username,userid from Dbo.tbluser where username= '%s '"% (uname)
query= "EXEC Sys.sp_cycle_errorlog"
Cursor.execute (query)
Conn.commit
Data=cursor.nextset ()
While not data:
Print (' Clear 43 error log completed! ')
Break
#清除代理日志
#query = "Select Username,userid from Dbo.tbluser where username= '%s '"% (uname)
query1= "EXEC Msdb.dbo.sp_cycle_agent_errorlog"
Cursor.execute (Query1)
Conn.commit
Data1=cursor.nextset ()
While not data1:
Print (' Clear 43 Agent log complete! ')
Break
#关闭连接, releasing resources
Cursor.close ()
Conn.close ()
com3= ' Pause '
Os.system (COM3)