Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
RETCODE rc1 = SQLDriverConnect(m_hConnect, hWnd, (_TUCHAR*)(LPCTSTR)sConnect, SQL_NTS,szFullConnect, sizeof szFullConnect, &avail, prompt);


In above statement of C++ code szFullConnect is suppose to return connection string
which is utilised in program.But in my code at one place this is coming as garbage
characters .Can anyone help me please to solve the issue.

What I have tried:

I googled lot but can not find concrete help
Posted
Updated 4-May-20 6:48am
Comments
Richard MacCutchan 4-May-20 4:02am    
Since we have no idea what source data is being processed it is impossible to know what actual characters should be returned, and we cannot see what you see. Are you sure you are not just mixing ASCII and Unicode?
adityarao31 4-May-20 4:12am    
Actually connection string returned by function is used to connect database
Richard MacCutchan 4-May-20 4:51am    
We know that. What we need to know is the actual definition of all the variables that are used in your call to SQLDriverConnect, and the actual data content of any that contain initial data. Please edit your question with this information, and also the characters that you see on return.

1 solution

The most common reason is that you have mismatched the character type in the string parameters.

Use SQLCHAR at all parameters and create or cast them properly. Depending on your compiler settings you may need conversion function. Type cast may not be enough.

btw: two type cast at one parameter is a strong hint that there is something very fishy ;-)
 
Share this answer
 
Comments
adityarao31 5-May-20 4:03am    
szFullConnect I have defined as SQLCHAR only

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900