Click here to Skip to main content
15,911,132 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I want to insert to database 3MB file.

faxMessage.FaxFile is a byte[] - 3MB file.

I use stored procedures, like below:

C#
using (SqlCommand sc = new SqlCommand("Myproc", sqlConnection))
{
    sc.CommandType = CommandType.StoredProcedure;
    sc.CommandTimeout = 100;
    sc.Transaction = transaction;

    sc.Parameters.Add(new SqlParameter("@inFaxFile", SqlDbType.VarBinary, faxMessage.FaxFile.Length));
    sc.Parameters["@inFaxFile"].Value = faxMessage.FaxFile;
    using (sc.ExecuteReader())
    {
    }
}


Should I change sth in SQL Server configuration ? It is simple VARCHAR(MAX) column.

I know, that maybe this is rookie question, but pleas help me.

UPDATE:
Or maybe I need to change sth in stored procedure? Here is the code:

BEGIN TRANSACTION
    BEGIN
        BEGIN TRY
            INSERT INTO [mgdb].[dbo].[Message]
                       ([NumberFrom]
                       ,[FaxFile])
                 VALUES
                       (@inNumberFrom
                       ,@inFaxFile)

            SET @outId = SCOPE_IDENTITY()

            COMMIT
        END TRY
        BEGIN CATCH
            SET @outId = -1
            ROLLBACK
        END CATCH
    END
Posted
Updated 23-Jul-11 18:29pm
v3
Comments
Eslam Mostafa 24-Jul-11 1:42am    
what is sth

1 solution

Use Image datatype for storing files. Change the datatype in your Table, your SP and your C# code and your code will work like a charm.
 
Share this answer
 
Comments
mnd017 24-Jul-11 9:18am    
So should I change sth in my C# code, in case of image datatype ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900