LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading nvarchar from MS-SQL?

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: 

DB_Snippet.png

 

Which runs fine but the second column of the returned string is giberish:

1984_0-1692603873238.png

 

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)

0 Kudos
Message 1 of 7
(1,089 Views)

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?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(1,067 Views)

Normal view:

1984_0-1692615320698.png

 

Hex view:

1984_1-1692615357374.png

 

Casted to varchar:

1984_2-1692615389329.png

 

(EDIT: and for now I can't even reproduce that parital unicode conversion.)

0 Kudos
Message 3 of 7
(1,063 Views)

@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 ?

0 Kudos
Message 4 of 7
(1,046 Views)


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)

0 Kudos
Message 5 of 7
(1,039 Views)

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?

 

0 Kudos
Message 6 of 7
(1,004 Views)

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.

0 Kudos
Message 7 of 7
(984 Views)