【问题标题】:pyodbc.Error: ('HY010', '[HY010] [Microsoft][ODBC Driver 13 for SQL Server]Function sequence error (0) (SQLFetch)')pyodbc.Error: ('HY010', '[HY010] [Microsoft][ODBC Driver 13 for SQL Server]函数序列错误 (0) (SQLFetch)')
【发布时间】:2021-10-20 16:29:53
【问题描述】:
    def gotorasp1(self):
        with pyodbc.connect(
                'DRIVER=' + driver + ';SERVER=' + server + ';PORT=1433;DATABASE=' + database + ';UID=' + username + ';PWD=' + password) as coca:
            with coca.cursor() as cola:
                cola.execute("SELECT * FROM Data")
        mac = cola.fetchone()
        log = self.login.text()
        pas = self.passw.text()
        ind = 0
        check = 0
        while ind != 5:
            if log == mac.Login:
                if pas == mac.Password:
                    un = mac.Lname
                    check = check + 1
                mac = cola.fetchone()
                ind = ind + 1
        if check == 1:
            self.username_labl_11.setText(_translate("MainWindow", un))
            self.login.setText("")
            self.passw.setText("")
            MainWindow.setMinimumSize(QtCore.QSize(1180, 800))
            MainWindow.setMaximumSize(QtCore.QSize(16777215, 16777215))
            desktop = QtWidgets.QApplication.desktop()
            x = (desktop.width() - MainWindow.width()) // 2
            y = (desktop.height() - MainWindow.height() - 90) // 2
            MainWindow.move(x, y)
            self.label_8.setStyleSheet("font: 9pt \"Montserrat\";\n""color:white")
            self.stackedWidget1.setCurrentWidget(self.page_2)
            self.comboBox.setItemText(0, _translate("MainWindow", dw + "  " + today.strftime("%d.%m.%Y")))
            cursor.execute(f"SELECT * FROM [dbo].[September] WHERE Day = {t}")
            row = cursor.fetchone()
            ...

此错误出现在这一行: mac = cola.fetchone() 而我,作为一个不是特别精通这个话题的人,绝对不能理解为什么。 我将非常感谢任何答案。

【问题讨论】:

    标签: python sql azure


    【解决方案1】:

    我喜欢一次抓取所有东西并将其放入列表中。我也喜欢抓取经常需要的列定义。

    column_definition = cola.description
    rows = cola.fetchall()
    

    然后在行上循环以执行您想要的操作,看起来您的代码在前 4 行上循环以查看是否有单个匹配项。无论如何,如果这消除了序列错误,您将需要更改该逻辑。

    【讨论】:

    • 原来问题是我在一个地方愚蠢地打破了标签,但还是谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-31
    • 2017-12-13
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多