python连接sqlserver数据库通常可以使用pymssql库和pyodbc库来实现,下面使用pyodbc展示连接的方式
database = "database" conn_info = 'DRIVER={SQL Server};DATABASE=%s;SERVER=%s;UID=%s;PWD=%s'%(database, host, user, password) mssql_conn = pyodbc.connect(conn_info) mssql_cur = mssql_conn.cursor() mssql_cur.execute("select DeviceCode,Count from [dbo].[S59M101PT10M_Aggrega]") row = mssql_cur.fetchall() line = pd.read_sql_query("select DeviceCode,Count from [dbo].[S59M101PT10M_Aggrega]",mssql_conn)