通过C脚本访问ODBC数据库。偶尔情况下回出现连不上,重新启动电脑后正常。连不上时会出现动作错误1007001,部分截图如下:

连接ODBC脚本如下:
#include "apdefap.h"
void OnOpenPicture(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
LINKINFO linkinfo;
char *p;
__object *cn,*rs;
char cSQLString[100],cConnString[100],s[100];
int num=0,i,flag=0;
int state;
linkinfo.LinkType=1;
linkinfo.dwCycle=0;
cn=__object_create("ADODB.Connection");
rs=__object_create("ADODB.Recordset");
ImportDestinationsToOrder(lpszPictureName);
SetPropWord(lpszPictureName,"DestinationList","ListIndex",0);
SetTagWord("Destination",1);
for(i=1;i<=4;i++)
{
sprintf(s,"Batch_house_1/Batch_Call_IDB.D%1d_Control_Mode",i);
if(GetTagWord(s)>0)
{
SetPropWord(lpszPictureName,"DestinationList","ListIndex",i-1);
SetTagWord("Destination",(WORD)i);
break;
}
}
ImportRecipeToOrderByFurnace(lpszPictureName,GetTagWord("Destination"));
sprintf(s,"Batch_house_1/Batch_Call_IDB.D%1d_Control_Mode",GetTagWord("Destination"));
strcpy(linkinfo.szLinkName,s);
SetLink(lpszPictureName,"ControlMode","OutputValue",&linkinfo);
sprintf(cConnString,"Provider=MSDASQL;DSN=BatchReporting;UID=;PWD=;");
cn->ConnectionString=cConnString;
cn->Open;
switch (GetTagWord("Destination"))
{
case 1:
{
strcpy(linkinfo.szLinkName,"");
SetLink(lpszPictureName,"TargetNumberOfBatches","OutputValue",&linkinfo);
strcpy(linkinfo.szLinkName,"Batch_house_1/Batch_Call_IDB.D1_Batch_Interval");
SetLink(lpszPictureName,"IntervalTarget","OutputValue",&linkinfo);
strcpy(linkinfo.szLinkName,"Batch_house_1/Batch_Call_IDB.D1_Time_To_Next_Batch");
SetLink(lpszPictureName,"IntervalActual","OutputValue",&linkinfo);
strcpy(linkinfo.szLinkName,"Batch_house_1/Formula_Data.Fo01_Cullet_Type");
SetLink(lpszPictureName,"Batch","OutputValue",&linkinfo);
//strcpy(linkinfo.szLinkName,"Batch_house_1/Formula_Data.Fo01_Mixer_In_Use");
//SetLink(lpszPictureName,"Mixer","OutputValue",&linkinfo);
strcpy(linkinfo.szLinkName,"Batch_house_1/Batch_Call_IDB.D1_Control_Mode");
SetLink(lpszPictureName,"Mode","OutputValue",&linkinfo);
if(GetTagWord("Batch_house_1/Batch_Call_IDB.D1_Control_Mode")!=0 || GetTagWord("Batch_house_1/Batch_Call_IDB.D2_Control_Mode")!=0 || GetTagWord("Batch_house_1/Batch_Call_IDB.D3_Control_Mode")!=0 || GetTagWord("Batch_house_1/Batch_Call_IDB.D4_Control_Mode")!=0)
{
flag=1;
sprintf(cSQLString,"Select * from RECIPE ORDER BY ID;");
rs=cn->Execute(cSQLString);
rs->MoveFirst;
while(!rs->eof)
{
if(rs->Fields(0)==GetTagSDWord("Batch_house_1/Formula_Data.Fo01_Formula_ID"))
break;
num=num+1;
rs->MoveNext;
}
SetPropWord("PicTree_Recipe.pdl","SourceRecipeListBox","ListIndex",num);
rs->Close;
}
else
{
SetPropWord(lpszPictureName,"RecipeList","ListIndex",GetPropWord("PicTree_Recipe.pdl","SourceRecipeListBox","ListIndex"));
}
switch(GetTagWord("Batch_house_1/Batch_Call_IDB.D1_Control_Mode"))
{
case 1:
{
SetPropWord(lpszPictureName,"Rectangle1","BackColor",0x00B400);
SetPropWord(lpszPictureName,"Rectangle3","BackColor",0xC0C0C0);
SetPropWord(lpszPictureName,"Rectangle4","BackColor",0xC0C0C0);
break;
}
case 2:
{
SetPropWord(lpszPictureName,"Rectangle1","BackColor",0xC0C0C0);
SetPropWord(lpszPictureName,"Rectangle3","BackColor",0x00B400);
SetPropWord(lpszPictureName,"Rectangle4","BackColor",0xC0C0C0);
break;
}
case 4:
{
SetPropWord(lpszPictureName,"Rectangle1","BackColor",0xC0C0C0);
SetPropWord(lpszPictureName,"Rectangle3","BackColor",0xC0C0C0);
SetPropWord(lpszPictureName,"Rectangle4","BackColor",0x00B400);
break;
}
default :
{
SetPropWord(lpszPictureName,"Rectangle1","BackColor",0xC0C0C0);
SetPropWord(lpszPictureName,"Rectangle3","BackColor",0xC0C0C0);
SetPropWord(lpszPictureName,"Rectangle4","BackColor",0xC0C0C0);
}
}
break;
}
}
if(flag)
{
SetPropWord(lpszPictureName,"ModeSelect","Operation",0);
//SetPropWord(lpszPictureName,"MixerSelect","Operation",0);
}
else
{
SetPropWord(lpszPictureName,"ModeSelect","Operation",1);
//SetPropWord(lpszPictureName,"MixerSelect","Operation",1);
}
cn->Close;
__object_delete(rs);
__object_delete(cn);
}