Database transaction information not available

本文介绍了当遇到“Database Transaction Information Not Available”错误时的两种常见解决方案。首先确保数据窗口的打开事件中包含了正确的数据库连接设置,其次检查应用程序级别的数据库连接是否已经建立。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

出现"Database transaction information not available"的问题.其实问题产生的很简单,就是“连接不上数据库”。

1,首先看你数据窗口中的open事件中有无增加这样一条语句:dw_1.settransobject(sqlca)。没这条语句可能会出现这样的提示,其实有的人会问到为什么会空白,其实再增加一条语句就可以了,那就是:

dw_1.retrieve()
if dw_1.rowcount()=0 then dw_1.insertrow(0)
dw_1.setfocus()

2,是你还是出现错误提示,你就要看你的APPLICATION中的open事件中,有无连接到数据库。其实写这个数据库连接程序很简单,只要你PB连接上数据库,直接到它的属性里复制到事件脚本中,把密码是*修改下自己的密码就OK了。。再在后面加上条语句:connect using sqlca;这样就定义了sqlca成为了一个全局变量中都一样的事务对象了。我具体的OPEN事件脚本如下:

SQLCA.DBMS = "MSS Microsoft SQL Server"
SQLCA.Database = "simdb"
SQLCA.LogPass = "xiaoqiu"
SQLCA.ServerName = "localhost"
SQLCA.LogId = "sa"
SQLCA.AutoCommit = False
SQLCA.DBParm = ""

connect using sqlca;

open(w_main)

def execute_add_robot(self, sn, ip, fp, device_type, pi_ip=None): try: with self.db_engine.connect() as conn: # Start a transaction with conn.begin(): columns = ["serialnumber", "dut_ip", "floorplan", "device_type", "team", "available", "base_type", "pi_ip"] values = { "serialnumber": sn, "dut_ip": ip, "floorplan": fp, "device_type": device_type, "team": "local", "available": "1", "base_type": "ChargeBase", "pi_ip": pi_ip if pi_ip else "" } insert_stmt = text(f""" INSERT INTO devices ({', '.join(columns)}) VALUES ({', '.join([f':{col}' for col in columns])}) """) conn.execute(insert_stmt, values) if not ip.replace('.', '').isdigit(): raise ValueError("Illegal IP format") status_ip = f"status_{ip.replace('.', '_')}" create_table_sql = f""" CREATE TABLE IF NOT EXISTS `{status_ip}` ( `robot_ip` varchar(17) NOT NULL DEFAULT '{ip}', `status_busy` BOOLEAN NOT NULL DEFAULT 0, `status_base` BOOLEAN NOT NULL DEFAULT 0, `status_error` BOOLEAN NOT NULL DEFAULT 0, `status_warning` BOOLEAN NOT NULL DEFAULT 0, `external_voltage` INTEGER NOT NULL DEFAULT 0, `battery_capacity` INTEGER NOT NULL DEFAULT 100, `can_be_started` BOOLEAN NOT NULL DEFAULT 1, `last_entry_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `last_event` VARCHAR(255) NOT NULL DEFAULT 'not-initialized', `remote_rf_port` INTEGER DEFAULT 8970, `installed_firmware` VARCHAR(50) NOT NULL DEFAULT 'not-initialized', `queue_status` VARCHAR(255) NOT NULL DEFAULT 'not-initialized', `queue_length` VARCHAR(255) NOT NULL DEFAULT 'not-initialized', `queue_task` VARCHAR(255) NOT NULL DEFAULT 'not-initialized', UNIQUE KEY `robot_ip` (`robot_ip`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 """ self.execute_on_db(create_table_sql) replace_sql = text(f"REPLACE INTO `{status_ip}` (robot_ip) VALUES (:ip)") conn.execute(replace_sql, {"ip": ip}) return "Device information submitted successfully!", True except SQLAlchemyError as e: return f"Database error: {str(e)}", False except ValueError as ve: return f"IP format error: {str(ve)}", False except Exception as ex: return f"Unexpected error: {str(ex)}", False 增加注释
03-27
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值