LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I insert an image(JPG) into a SQL database?

thanks for the thread - it looks like the same 8kb limit is built into TestStand 4.2.1 😞

 

I spend a full day figuring out why I could not upload anything larger than this!  I need to upload measurement graphs during automated testing.

 

 

0 Kudos
Message 11 of 21
(8,387 Views)
Howdy folks!
 
I wanted to let you know that I am successfully inserting large amounts of binary data into an "image" field of an SQL Server 2008 database directly from LabVIEW 2009 using the DB connectivity VIs.  I am breaking my data up so it's easier for users to examine subsets of it, so each of my "image" fields is only holding about  a megabyte, but this is still way beyond the 8K limit you guys are bumping up against.  I realize "image" is deprecated, but for now it suits my purposes.  I've stressed this out by loading several gigs of data (in 1MB chunks) and it works like a champ.
 
If you are still interested in this problem I'll write a small example VI to show how I'm doing it and post it here.
 
I have discovered that in order for this to work it is important to NOT use a "data source" as the DB connection specified in your UDL file.  When I tried this I ran into the same limitation you folks have been hitting:  "String Data Right Truncation".  What I did was, in my UDL specification (also called "data link properties"), I chose "SQL Server Native Client 10.0" as my "provider", then set my "connection" to point to my SQL Server instance and picked the database I wanted to use.  Clicked OK to save the settings to the UDL file, and that was it!
 
One thing to note is that I am using SQL Server Native Client 10.0.2531, which you can get here: http://www.microsoft.com/downloads/details.aspx?familyid=B33D2C78-1059-4CE2-B80D-2343C099BCB4&displa....  Scroll down to a little past half way down the page to get to the Native Client download.  My understanding is that 10.0.1600 had at least one weird bug that caused people grief with floating point numbers.  Don't know if it would have an impact on the "right truncation" error, but it's not worth the risk.  1600 is known to be buggy, so get rid of it if you are running it!  You can see the version you are running in the "data sources (ODBC)" tool; click "add...", then look in the version column of the "create new data source" window that pops up on the "SQL Server Native Client 10.0" row.  Typically this will be the last row in the list.  The version number is formatted weirdly here; it shows up as "2007.100.2531.00".  However other places I've seen it referred to as "10.0.2531".  Go figure.
 
Anyway, I will be happy to extract a small working example of LabVIEW using DB connectivity VIs to insert and retrieve large binary data to/from an SQL Server DB if anyone here would find it useful; just let me know.
0 Kudos
Message 12 of 21
(8,339 Views)

I would like to see how you do it 🙂

0 Kudos
Message 13 of 21
(8,317 Views)
So would I.  I'm currently working with databases, LV2009, and TestStand 4.2.1
- tbob

Inventor of the WORM Global
0 Kudos
Message 14 of 21
(8,296 Views)

The attached VI establishes a connection to a DB, writes a string, a double, and an 8MB 3D array of doubles to a table with 3 fields.  Then it reads the data out of the DB and displays it along side the values it initially saved to the DB so you can compare them.  Keep in mind that it writes a new row to the DB every time you execute it, and only the last row in the DB will match the input values you see during any particular run, so as you run it subsequent times you will see historical values in the first N-1 rows retrieved and your current "initial" values in the Nth row.

 

Below is the schema that the VI expects your DB to conform to.  You can name your DB anything you like; mine is named leh_test.

 

USE leh_test

 

DROP TABLE big_data

            

CREATE  TABLE [big_data] (

  "id" INT NOT NULL IDENTITY(0,1),

  "big_text" VARCHAR(8000) NOT NULL,

  "num" REAL NOT NULL,

  "can_hold_2gb" image NOT NULL

  PRIMARY KEY ("id")

)


After you have loaded the schema into your DB, load the VI, enter the path and name of the UDL file that contains your connection information, then run the VI and watch what happens.  Every time it is executed it will insert a new row into the DB, then it will display every row in the DB, pausing with a dialog after each row is loaded.

 

The VI was written in Labview 2009 and was tested running against SQL Server 2008 Express, which has the wonderful feature of being free.  What other redeeming qualities SQL Server has is an open question. 🙂  I ran it about a dozen times and it worked perfectly for me every time.  If you run into difficulties with it I'll be happy to help where I can, but bear in mind that it's will almost certainly be some kind of problem with your environment.

 

This VI is light on error checking and user friendliness, but should get the point across well enough.

 

Enjoy!

Lynwood Hines, CLAD

 

0 Kudos
Message 15 of 21
(8,274 Views)

hi there i'm also facing difficulty in retrieving image from the database could anyone covert the vi to labview8.6 version please because i could not open the 2009 version to see the VI

0 Kudos
Message 16 of 21
(8,053 Views)
0 Kudos
Message 17 of 21
(8,043 Views)

thanks for the vi

0 Kudos
Message 18 of 21
(8,041 Views)

Thanks for sharing.

0 Kudos
Message 19 of 21
(7,666 Views)

I would just like to answer some of the problems users were talking about earlier on in this topic.

SQL Server 2000 had a maximum limit of 8,000 characters for any one column, regardless of the datatype used, AND in-fact a single ROW could also contain no more than 8,000 characters - hence the "rigth truncation" error appearing.

 

This limit is no longer present in the Server 2005 and 2008 versions

 

Instead of using a UDL File we use the Connection String approach eg. For SQL Server 2005

 

Driver={SQL Native Client}; Server=MC4332\SQLEXPRESS;  Database=database_name; Uid=username; Pwd=password;

 

You can check to see if this Driver is present by looking in your ODBC Data Souce Administrator in the Control Panel

 

For SQL Server 2008 we use:

 

Driver={SQL Server Native Client 10.0}; Server=MC6603\SQLEXPRESS;  Database=database_name; Uid=username; Pwd=password;

 

But as Lynwood mentioned above you will probably need to download this driver if you have a Windows XP systems.

 

This website is an excellent source of all the different types of connections strings - http://connectionstrings.com/

 

Chris

0 Kudos
Message 20 of 21
(7,557 Views)