Link to home
Start Free TrialLog in
Avatar of rbhargaw
rbhargawFlag for United States of America

asked on

[Microsoft][SQL Native Client]Invalid character value for cast specification

I have an old code in VC++ and MFC which is creating command to call a stored procedure like this:

CString spText;
      spText.Format ( "{call GetMailData(%d,%d,%s ,%s,%d)}", activityRecordData.entityNumber,
            activityRecordData.rttiTypeID, activityRecordData.addrTypeID, activityRecordData.corrMethID,
            activityRecordData.docGroupID)

Now while executing I am receiving error  "[Microsoft][SQL Native Client]Invalid character value for cast specification" even though the SP works fine in SQL Client.

The reason I think is %s because if I remove %s variables from the code and comment varchar parameters in Stored procedure, it runs properly. Any way to pass the string variables properly?





To run the SP:

GetMailData 3040047,10,HOME,SMTP,3060

notice that I am not passing HOME and SMTP in quotes..

ALTER PROCEDURE [dbo].[GetMailData]  
   @EntNo int/* IN must - entity Number*/,
   @rttiTypeID int/* IN must - entity type*/,
   @addrTypeID varchar(4)/* IN optional, address type Id (Home, Offc, etc.)*/,
   @corrMethID varchar(4)/* IN optional, correspondence method ID*/,
   @docGroupNo int/* IN must - document group number*/
WITH RECOMPILE

Open in new window

Avatar of jkr
jkr
Flag of Germany image

Could you post the declaration of 'activityRecordData'?
Avatar of rbhargaw

ASKER

const t_activityRecordData &activityRecordData

typedef struct {
      int holdingID;
      int refHoldingID;
      int refHoldingType;
      int docGroupID;
      char spName [MAXBUFLEN];
      int entityNumber;
      short rttiTypeID;
      char addrTypeID [CODE_LEN+1];
      char corrMethID [CODE_LEN+1];
} t_activityRecordData;
ASKER CERTIFIED SOLUTION
Avatar of rbhargaw
rbhargaw
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Weird... but if it works.
string literals always need to be quoted.

you need to make sure that the strings don't have a single quote ' character in the text. if so they must be escaped by doubling them.

Sara
I added the single quote around '%s' and the solution worked