myHandle:=LoadLibrary('DBConn.dll'); //载入DLL
      @SQLConnLib:=GetProcAddress(myHandle,'CreateSQLServerConn');//获取到DLL中的函数
      sqlconnection:=SQLConnLib('.','master','','');
      QueryData:=sqlconnection.DoQuery('select * from sys.databases');
      //连接access数据库获取特征表
        @accessConnLib:=GetProcAddress(myHandle,'CreateAccessConn');//获取到DLL中的函数
        accconn:=accessConnLib('fpconfig.dat','FPSearchInfor');
       if not accconn.GetConnectState then
       begin
         ShowMessage('软件数据信息读取失败,请检查access数据资料库!');
       end;
      accquery:= accconn.DoQuery('select FPTableString from FPSearchInfor ');     while not  accquery.Eof do
     begin
         str:=accquery.FieldByName('FPTableString').AsString;
         ShowMessage(str);
     while not (QueryData.Eof) do
     begin
       // ShowMessage(VarToStr(QueryData.Recordset.Fields['name'].Value));
       // flag:=true;
       // sqlconn:=SQLConnLib('.','UFDATA_666_2014','','');
         sqlconn:=SQLConnLib('.',''+QueryData.Recordset.Fields['name'].Value+'','','');
         j:=1;
        table:=True;
         //str:=accquery.FieldByName('FPTableString').AsString;
        //查询dat文件中一列表是否存在多个表名
        if(pos('|',str)=0)then
       begin
          //ShowMessage('select name from sysobjects where name in ('''+accquery.Recordset.Fields['FPTableString'].Value+''')');        sqlquery:=sqlconn.DoQuery('select name from sysobjects where name in ('''+str+''')');
        //showmessage(sqlquery.Recordset.Fields['name'].Value);
        //查询数据库中是否存在特征表
        if sqlquery.RecordCount>0 then
        begin
          showmessage(QueryData.Recordset.Fields['name'].Value+' is u8');
        end
        else if sqlquery.RecordCount=0 then
        begin
         table:=false;
        end;
          sqlquery.Next;
          end;
         //QueryData.Next;
        while (pos ('|',str)>0) and ( table = true ) do
         begin
           i:=pos('|',str);
           FPstr:=Copy(str,1,i-1);
            ShowMessage('select name from sysobjects where name in('''+FPstr+''')');
           sqlquery:=sqlconn.DoQuery('select name from sysobjects where name in('''+FPstr+''')');
           //showmessage(sqlquery.Recordset.Fields['name'].Value);
        if(sqlquery.RecordCount = 0) then
         //showmessage(QueryData.Recordset.Fields['name'].Value);
         begin
           table:=False;
           continue;
         end;
        if(sqlquery.RecordCount > 0) then
          begin
        Delete(str,1,i);
        //ShowMessage(str);
        FPstr:=str;
         if(pos('|',str)=0)then
         begin
        sqlquery:=sqlconn.DoQuery('select name from sysobjects where name in('''+FPstr+''')');
        if(sqlquery.RecordCount = 0) then
         //showmessage(QueryData.Recordset.Fields['name'].Value);
         begin
           table:=False;
           continue;
         end;         //sqlquery.Close;
         // sqlquery.ClearFields;
         // sqlquery.Open;
         end;
          sqlquery.Next;         end;        //若为true,则该数据库包含这一列的数据库表
        //inc(j);
       end;
       if (table=true )then
        begin
         showmessage(QueryData.Recordset.Fields['name'].Value+'is u8');
        end;       QueryData.Next;
      //ShowMessage(QueryData.Recordset.Fields['name'].Value);
      end;      accquery.Next;
     end;access violation at address 00402256  in module

解决方案 »

  1.   


     myHandle:=LoadLibrary('DBConn.dll'); //载入DLL
          @SQLConnLib:=GetProcAddress(myHandle,'CreateSQLServerConn');//获取到DLL中的函数
          sqlconnection:=SQLConnLib('.','master','','');
          QueryData:=sqlconnection.DoQuery('select * from sys.databases');
          //连接access数据库获取特征表
            @accessConnLib:=GetProcAddress(myHandle,'CreateAccessConn');//获取到DLL中的函数
            accconn:=accessConnLib('fpconfig.dat','FPSearchInfor');
           if not accconn.GetConnectState then
           begin
             ShowMessage('软件数据信息读取失败,请检查access数据资料库!');
           end;
          accquery:= accconn.DoQuery('select FPTableString from FPSearchInfor ');     while not  accquery.Eof do
         begin
             str:=accquery.FieldByName('FPTableString').AsString;
             ShowMessage(str);
         while not (QueryData.Eof) do
         begin
           // ShowMessage(VarToStr(QueryData.Recordset.Fields['name'].Value));
           // flag:=true;
           // sqlconn:=SQLConnLib('.','UFDATA_666_2014','','');
             sqlconn:=SQLConnLib('.',''+QueryData.Recordset.Fields['name'].Value+'','','');
             j:=1;
            table:=True;
             //str:=accquery.FieldByName('FPTableString').AsString;
            //查询dat文件中一列表是否存在多个表名
            if(pos('|',str)=0)then
           begin
              //ShowMessage('select name from sysobjects where name in ('''+accquery.Recordset.Fields['FPTableString'].Value+''')');        sqlquery:=sqlconn.DoQuery('select name from sysobjects where name in ('''+str+''')');
            //showmessage(sqlquery.Recordset.Fields['name'].Value);
            //查询数据库中是否存在特征表
            if sqlquery.RecordCount>0 then
            begin
              showmessage(QueryData.Recordset.Fields['name'].Value+' is u8');
            end
            else if sqlquery.RecordCount=0 then
            begin
             table:=false;
            end;
              sqlquery.Next;
              end;
             //QueryData.Next;
            while (pos ('|',str)>0) and ( table = true ) do
             begin
               i:=pos('|',str);
               FPstr:=Copy(str,1,i-1);
                ShowMessage('select name from sysobjects where name in('''+FPstr+''')');
               sqlquery:=sqlconn.DoQuery('select name from sysobjects where name in('''+FPstr+''')');
               //showmessage(sqlquery.Recordset.Fields['name'].Value);
            if(sqlquery.RecordCount = 0) then
             //showmessage(QueryData.Recordset.Fields['name'].Value);
             begin
               table:=False;
               continue;
             end;
            if(sqlquery.RecordCount > 0) then
              begin
            Delete(str,1,i);
            //ShowMessage(str);
            FPstr:=str;
             if(pos('|',str)=0)then
             begin
            sqlquery:=sqlconn.DoQuery('select name from sysobjects where name in('''+FPstr+''')');
            if(sqlquery.RecordCount = 0) then
             //showmessage(QueryData.Recordset.Fields['name'].Value);
             begin
               table:=False;
               continue;
             end;         //sqlquery.Close;
             // sqlquery.ClearFields;
             // sqlquery.Open;
             end;
              sqlquery.Next;         end;        //若为true,则该数据库包含这一列的数据库表
            //inc(j);
           end;
           if (table=true )then
            begin
             showmessage(QueryData.Recordset.Fields['name'].Value+'is u8');
            end;       QueryData.Next;
          //ShowMessage(QueryData.Recordset.Fields['name'].Value);
          end;      accquery.Next;
         end;
    end;
      

  2.   

    没仔细看,Delphi数据库只需要连接一次即可使用,除非是网络异常或其他问题导致连接失败时,需要重新连接。 如果数据库连接信息时封装在dll中的话,只需调用一次就行了,重复调用时,需要及时释放myHandle资源。
      

  3.   

    soga,连接不同的数据库是不是也要把资源释放,不然会导致????
      

  4.   

    如果所有数据库连接信息都封装在DLL内,只需释放myHandle就可以,如果是多个DLL,需要释放多个myHandle资源。