Home Forums SQL Server 2005 Administering Implicit conversion from data type sql_variant to varchar is not allowed. Use the CONVERT function to run this query. RE: Implicit conversion from data type sql_variant to varchar is not allowed. Use the CONVERT function to run this query.

  • susaabraham (2/21/2009)


    db.AddInParameter(cmd, param.Key.ToString(), DbType.Object, param.Value);

    There's your problem. According to the data type mapping on MSDN (http://msdn.microsoft.com/en-us/library/cc716729.aspx), DBType.object maps to SQL varient. So you're trying to pass all the parameters as SQL_variants and when one won't convert, you will get this error.

    If you could change the code so that the types are set correctly for the parameters, the problem should go away. Either add the type to the hybridDictionary or infer the correct type when adding the parameter

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass