views:

24

answers:

1

Uploading files from asp.net to SQL Server 2008, after I upload to SQL Server I see the attach content is: 0x89

My stored procedure accepts : @AttachContent varbinary,

Below is my code how I am uploading.

public bool AttachmentInsert(int mimeTypeId, string attachFileName,
                             byte[] attachContent)
{
   using (DataContextDataContext dc = conn.GetContext())
   { 
      int attachId =  (int)dc.spAttachment_Insert(mimeTypeId, attachFileName, 
                                                  attachContent).ReturnValue; 
      if (attachId != 0)
      {
         return true;
      }
      return false;
   }
}

[Function(Name="dbo.spAttachment_Insert")]
public ISingleResult<spAttachment_InsertResult> spAttachment_Insert(Name="AttachContent", DbType="VarBinary(1)")] System.Data.Linq.Binary attachContent,        
{
   IExecuteResult result = 
       this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), 
                              mimeTypeID, attachFileName, attachContent);
   return ((ISingleResult<spAttachment_InsertResult>)(result.ReturnValue));
} 

Any help how to correct.

+3  A: 
DbType="VarBinary(1)"

You are truncating the content to 1 byte. Use VarBinary(max) instead.

Remus Rusanu