rbhargaw
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.entityN umber,
activityRecordData.rttiTyp eID, activityRecordData.addrTyp eID, activityRecordData.corrMet hID,
activityRecordData.docGrou pID)
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?
CString spText;
spText.Format ( "{call GetMailData(%d,%d,%s ,%s,%d)}", activityRecordData.entityN
activityRecordData.rttiTyp
activityRecordData.docGrou
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
Could you post the declaration of 'activityRecordData'?
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;
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
I added the single quote around '%s' and the solution worked