用adoconnection连接sql数据库,在设计时,从文本中读出数据库连接串然后付给adoconnection设置adoconnection.active:=true,当数据库连接不正确得时候,虽然错误捕捉到了,但是出现"错误变量类型转换"(invalid variant type conversion),并且,不断弹出新得窗口,各位仁兄帮忙了
以下是代码,       DM.ADOConnection.Connected :=False;
       DM.ADOConnection.ConnectionString :=mystr;       
     try
       DM.ADOConnection.Connected :=true;
     except
         MessageBox(handle,'客户端配置错误','错误',MB_ok+MB_ICONERROR);
         exit;
     end;

解决方案 »

  1.   

    我是这样的,没有问题呀:
            s_strSystemPath:=ExtractFilePath(Application.ExeName);        ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+s_strSystemPath+'database\医教素材库.mdb;Persist Security Info=False';
            ADOConnection1.Connected:=true;
    还有,要不行,你可以重新做一个试试
      

  2.   

    if ADOCntGlobal.Connected then ADOCntGlobal.Connected := false;
          ADOCntGlobal.CommandTimeout := 45;
          ADOCntGlobal.ConnectionTimeout := 45;
          ADOCntGlobal.ConnectionString := '';
               ADOCntGlobal.ConnectionString := 'Provider=SQLOLEDB.1;Password=' + 密码   + ';Persist Security Info=True;User ID=' + 登陆用户名 + ';Initial Catalog=数据库名;Data Source=' + sql实例名      if not ADOCntGlobal.Connected then ADOCntGlobal.Connected := true;
        except
          begin
            Gdberror := true;
            msgp(Gcntinfo, mb_ok + MB_ICONerror);
          end;
        end;
        ADOCntGlobal.Close;