08-21-2023 04:07 AM
Hi,
I need to read some data from an MS-SQL database with labview by running the pre-written stored procedures provided by our customer. The code I have is:
Which runs fine but the second column of the returned string is giberish:
I have really very-very little idea how to use a Labview with a database, but after googling a while it seems that the issue is caused by that the 2nd column is an "nvarchar". Also by googling I tried have copied the query of the stored procedure to labview (so instead of calling the stored procedure, I called the query directly) and changed the query from this:
SELECT BR.ID, BR.ModuleID, BR.IS, BR.WR FROM Results
to this
SELECT BR.ID, CAST (BR.ModuleID AS VARCHAR), BR.IS, BR.WR FROM Results
With my code runs just fine and the second column is prefectly fine. As I said, I have no expereinces with DBs, but is there a way to do this CAST on the returning values coming from the stored procedure?
(I also found some tips of doing a unicode conversion which I tried, with partial success because it seems that only part of the real value is returned on that way. So if I convert the giberish looking chrs to unicode then I only get the first part of the string, not everything)
08-21-2023 05:51 AM
Hi 1984,
@1984 wrote:
Which runs fine but the second column of the returned string is giberish:
How do the strings look like in hex display mode?
08-21-2023 05:56 AM - edited 08-21-2023 06:05 AM
Normal view:
Hex view:
Casted to varchar:
(EDIT: and for now I can't even reproduce that parital unicode conversion.)
08-21-2023 07:35 AM
@1984 a écrit :
I have really very-very little idea how to use a Labview with a database, but after googling a while it seems that the issue is caused by that the 2nd column is an "nvarchar". Also by googling I tried have copied the query of the stored procedure to labview (so instead of calling the stored procedure, I called the query directly) and changed the query from this:
SELECT BR.ID, BR.ModuleID, BR.IS, BR.WR FROM Results
to this
SELECT BR.ID, CAST (BR.ModuleID AS VARCHAR), BR.IS, BR.WR FROM Results
With my code runs just fine and the second column is prefectly fine. As I said, I have no expereinces with DBs, but is there a way to do this CAST on the returning values coming from the stored procedure?
(I also found some tips of doing a unicode conversion which I tried, with partial success because it seems that only part of the real value is returned on that way. So if I convert the giberish looking chrs to unicode then I only get the first part of the string, not everything)
Any chance to get the possibility to change the stored procedure itself ?
08-21-2023 07:51 AM
Any chance to get the possibility to change the stored procedure itself ?
Working on that but its very unlikely as the DB is maintained by a 3rd party company. (who probably doesnt care too much about this (seemingly) labview related problem)
08-22-2023 02:46 AM
I don't think, that this is a LABVIEW problem. It could be lousy, when it comes to character sets.
MYSQL unterstands the keyword nvarchar but it will be translated to varchar with UTF-8. Also important could be the global character set and/or the character sets of the session, schema, table, column. So we need much more information. Are you able to export the schema or parts of the table including the create statements?
08-22-2023 08:05 AM
I'm unsure if this is related but the collation of the db is Latin1_General_CI_AS. As I heard this in not unicode and as I heard this determines if by default the nvarchar stores values in unicode or if it doesnt. I also heard that its possible that whoever filled the db with values used a software which sent the values as unicode to the db and as nvarchar can store unicode it was stored like that despite the collation.
As you might noticed that all of these are wild guesses although the guy told me this is normally a pretty convincing one.