473,382 Members | 1,367 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

SQL XML Bulk Load varbinary(8000) to varbinary(MAX)

dbudry
4
I have a program that I developed that builds an XML file that stores base64binary data from images stored in SQL Server. The XML file along with the schema get transfered, then another program picks them up and uses the SQLXMLBULKLOADLib to insert the XML data based mapped with a Schema file back into SQL Server.

The problem is that when it imports it into SQL Server, it creates a varbinary(8000) data type instead of varbinary(MAX) data type. It is cutting off some of my data and thus my images will not show up on the website. How do I get it to create the table with varbinary(MAX)?

Help?

Below is example of my schema file:
<xs:schema id="ROOT" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="tblBioApproved">
<xs:complexType>
<xs:attribute name="BioPictureA" type="xs:base64Binary" />
<xs:attribute name="BioPictureTypeA" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:schema>
Mar 24 '10 #1
7 3978
dbudry
4
In my program, I checked to see if it was updating the table that needed the varbinary(max) datatype for. When the program comes to the needed xml file, I changed the SQLXMLBULKLOAD to not to drop the table, then I clear out the sql table, alter the data type to varbinary(max) just to be sure, and then import my xml file with the schema.

This is not the way that I wanted it to work because I had to hard code the table name in the program. My hopes were to have everything dynamically driven so I didnt have to hard code any table names.

Though I found a solution that worked for me, If anyone is able to answer my original question, I would redesign the program.

Thanks
Mar 29 '10 #2
NeoPa
32,556 Expert Mod 16PB
You seem to be implying (I can't see where you say much about your problem explicitly) that you are using an approach where the data is uploaded into a new table. Is there any reason why you wouldn't be loading into a previously created, and potentially cleared down, table?

Excuse me if this is a dumb question. I am no Asp.NET programmer, but I have a fair amount of database experience, with even some limited SQL Server thrown in.
Mar 30 '10 #3
dbudry
4
No, that is a excellent question. I developed it this way to avoid doing as much programming or manual work as possible. My objective was to only change the locally stored code but not the remotely stored program. So no matter what tables or data I add in the future, as long as I pass the needed data, and schema, the remote program would pick it up, and import it into the SQL database.

Using the existing table and sizing down the fields would offer better performance, I just didnt want the extra work of maintaining the tables on the other side.

Unfortunatly though, everytime you use the BULKLOAD and clear out the table, the schema with "Type" of "base64binary" will not create the table with with varbinary(MAX) so I had to make an one exception with that table unlike the others.

Did that make since? Sorry it took so long for me to get back, but thank you for your reply.
Apr 5 '10 #4
Frinavale
9,735 Expert Mod 8TB
I don't understand what you're doing probably because I cannot picture what your application is.

Is it a Web Service?
Do you have a desktop client application consuming the web service?


Or is this an ASP.NET web application?
Apr 5 '10 #5
dbudry
4
I have a set of programs that run on a virtual machine locally. Every day at 3am the program runs collecting data from a local SQL server in XML format, then using WinSCP I transfer the XML files with schemas that I build via SFTP over to my hosting server and drop the contents off in a folder. At around 3:30 AM on the hosting server has another set of programs run that I designed that grabs the XML files with the schema's and Bulk Uploads them to the SQL server on the host.
Apr 5 '10 #6
NeoPa
32,556 Expert Mod 16PB
dbudry: No, that is a excellent question. ...
My turn to apologise for my delayed response.

Your answer's a good one, but I'm afraid tells me more than anything else, that I can't help you. Sorry, and good luck.
Apr 8 '10 #7
Jerry Winston
145 Expert 100+
I think you're just missing a few planning steps. Your problem is creating tables, not necessarily importing (which it seems like you have mastered) or formatting. If your table name is inconsistent but your table structure is always the same ie (ID BIGINT, myXMLData VARBINARY(MAX), descData VARCHAR(1024)) you need table-creating function on the database side or the application side. In an application-side solution you would add something like this before your upload statement:
Expand|Select|Wrap|Line Numbers
  1. fn_buildTable(myTableName,myDBConnection)
  2.  
Where the application function takes the table name as an argument.

The TSQL solution would involve stored procedures and go something like this:
Expand|Select|Wrap|Line Numbers
  1. CREATE sp_uploadXML(newTableName,field1,field2,field3)
  2. AS
  3.     sp_createTable(newTableName)
  4.     sp_saveXMLData(newTableName,field1,field2,field3)
  5. END
  6.  

Can you share the basic gist of what your current table-creating code looks like?


I don't know if you're terribly interested in SQL Server, however, I wonder if you considered implementing, scheduling, and automating your Extract Transform and Load operations using SQL Agent. There's a wealth of XML and ETL support in SQL 2005 that I think you could benefit. You're ETL process isn't broke so it doesn't need fixing but you might want to checkout the OPENXML, OPENROWSET and DECLARE @x XML code. They make my life so much easier when I'm designing ETL processes with XML.
Aug 10 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to...
2
by: Bill Nguyen | last post by:
I need sample code to insert binary file (mappoint map file) into a varbinary column using VB.NET. Please help! Thanks Bill
1
by: Karch | last post by:
I am doing some experimenting with serialization (for use with Service Broker) and I am having a problem converting from a .NET DateTime (in the client application) to a SqlDbType.VarBinary (as...
7
by: gsauns | last post by:
Not sure if this is belongs here, or maybe in SQL... I have a SQL Server 2005 database where I store a varbinary(MAX) field. In my Web form, I allow the user to upload a photo to the database....
2
by: tindersticks | last post by:
Hi Can someone please post the simplest script that will allow an asp page read and write to/from m a MS SQL varbinary(max) field. ie image or doc/pdf etc is converted to relevant format and...
1
by: Gilad | last post by:
Hi I moved to SQL Server 2005 (from 2000) and noticed there is a better variable to deal with binary arrays. I hava a table that hold 9 columns of images (BLOB). each array has a different size...
4
by: Martin Horst | last post by:
Hi, I've got an application which is written in .Net 1.1. When I try to write a varbinary(max) field using the SqlCommand and SqlParameter classes I got an exception like this: "The...
1
by: quartrj | last post by:
For number of security reasons I can't use the Openrowset - Bulk option does any know of another way to load files into this data type.
1
by: quintonmartin | last post by:
Here's my problem. I have a client application that uses a web service for data access. I can read/update many records in many tables, however, I am not getting what I expect for a varbinary(max)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.