nvarchar to varbinary(max) is not allowed

Thread is closed for posting
4 posts, 0 answers
  1. Dave
    Dave avatar
    40 posts
    Member since:
    Jun 2007

    Posted 13 Sep 2009 Link to this post

    Ok, I am at wits end and hope someone can help me because I cannot figure out this problem.

    I have a RadUpload in a nestedviewtemplate of a RadGrid that I want to use to store PDF, XLS, DOC, etc. files to my database.  At present I am using the development SQL Server Express 2008 with VS2008.  Originally I went to fast and easy by using SQLDataSources to drive my grids and provide the select, update, and insert funcitonallity but intermittently received the error:

    Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.


    After searching around the Telerik site I stumbled on the Upload and open documents in a SQL database demo in the code library, took some time wrapping my head around the C# code and figured out what made it tick.  This worked flawlessly for every file I tried to upload so I thought, this is it!  I converted this demo app to work with my SQL Express table, added the extra fields I wanted stored with my data, popped a reference to the FileUpload.BLL into my application and finally got everything running as expected, well until I tried to upload a file and blast you implict conversion!

    I then spent even more time researching the interweb for a possible solution to this problem and found some vague reference to converting the System.Link.Data.Binary to a byte[] array and changed the FileUpload.BLL line from:

    private System.Data.Linq.Binary _FileBinary; to private byte[] _File_Data;

    and then changed the inserting code from:

     fileStorage.File_Data = new System.Data.Linq.Binary(file.File_Data);

    to:

     fileStorage.File_Data = (byte[])file.File_Data.ToArray();

    I rubbed my hands together gleefully, fired up the app, inserted a file and.....BLAST IT, error again.

    Well, now I am all out of ideas as to what is throwing this error and have no clue what to try next.  Even with all of that, know what the kicker is?  My record is apparently saving in the database and the binary data appears to be there since I can hit the back button, refresh the grid and there it is.  So, please one of you smarter than me folks tell me what I can do to get this working, even if it is just surpressing this error.  I REALLY need this database online to track my project.
  2. Christopher Bishop
    Christopher Bishop avatar
    50 posts
    Member since:
    May 2008

    Posted 16 Sep 2009 Link to this post

    The error you are getting is being caused by to different dataTypes that are not directly convertable and what it is telling you to do is basicly say CONVERT(varchar(10), GetDate(), 101) (example lol which just converts a datetime to a string in this format 1/1/1900)...

    This simplest way to fix this problem is to change your fields to match (not sure why you are using nvarchar on a binary field) but be that as it may this is a database related issue and is easily fixed by just making sure that your fields match up like nText etc.


  3. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1600 posts

    Posted 17 Sep 2009 Link to this post

    Hi Sam,

    As stated, your fields most probably do not mach. Please, refer to the following help article on how convert works. You can look here as well. If you are still having troubles to get it work, please open a support ticket and send us a sample that covers your scenario and reproduces the error. We will do our best to have it fixed.



    Best wishes,
    Genady Sergeev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  4. Dave
    Dave avatar
    40 posts
    Member since:
    Jun 2007

    Posted 18 Sep 2009 Link to this post

    Thanks for your answers, but the fact of the matter is that the data I was uploading did match the VarBinary(MAX) type and I have no idea where the whole nvarchar to varbinary was coming from.  It is a moot point though, I got really tired of banging my head against the wall the day I posted the message, shut everything down, decided a while latter that the lumps on my forehead were going down and decided to try again.  I just booted up, fired VS, opened the project, started a test run and the dang thing has operated flawlessly since.
Back to Top