CS架构的MySQL数据链接问题

2016-03-1813:03:56SQLSTATE = 08S01
[MySQL][ODBC 5.3(a) Driver][mysqld-5.1.73-community]MySQL server has gone away

之前写一个短信平台接口
就是从SqlServer检索到数据后往MySQL插入数据
因为对MySQL不熟悉,所以程序运行后每隔一段时间就会报sql错误
错误信息如上
此错误是因为MySQL如果长时间链接没操作会自动断开连接引起的
解决的办法就是每次要操作的时候无论是否已经断开连接都重新连接一次

     if gf_connect(sqlca_pf,gs_ini,'platform') then

     else
    fun_write_log('  重连平台数据库失败:'+sqlca_pf.sqlerrtext)
     end if
//插入MySQL数据库
 Insert into sms_outbox  (sismsid, extcode, destaddr, messagecontent,  
       reqdeliveryreport,msgfmt,sendmethod,requesttime,applicationid)VALUES   
        (:ls_id, '1', :ls_phone, :ls_message, 1, 15, 0,:ls_datetime, 'checkdb') 
using sqlca_pf; 
if sqlca_pf.sqlcode<> 0 then 
fun_write_log('  插入失败信息:'+ls_info)
fun_write_log(sqlca_pf.sqlerrtext)
else 
fun_write_log('  插入成功信息:'+ls_info)
commit using sqlca_pf;
end if

posted on 2016-03-31 10:25  MaxGeek  阅读(48)  评论(0)    收藏  举报