Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net FileUpload control works on server but not for clients
    text
    copied!<p>I have a strange thing going on with the .net fileupload control. If I remote desktop to the server that houses the web app and db server, I am able to upload files and store them into a varbinary(max) column.</p> <p>However, when clients connect to the web server from their desktop, then can do all the things they need to such as browsing web pages, fill out forms that store/save data to the database, etc.</p> <p>However, when they try to upload a pdf to the sever, the following exception occurs: The web app uses .net 3.5, the db is sql 2005, and code is c#. And insights would be welcomed. Code and Exception below. Any insights will be welcomed.</p> <pre><code>protected void btnSave_Click(object sender, EventArgs e) { int intDocLen = 0; string str = ""; Stream objStream = default(Stream); SqlConnection Conn = default(SqlConnection); SqlCommand cmdUploadDoc = default(SqlCommand); string ConnString = null; lblMessage.Text = ""; try { if (FileUpload1.HasFile) { Guid NewDOCGUID = System.Guid.NewGuid(); intDocLen = FileUpload1.PostedFile.ContentLength; byte[] Docbuffer = new byte[intDocLen]; objStream = FileUpload1.PostedFile.InputStream; objStream.Read(Docbuffer, 0, intDocLen); ConnString = ConfigurationManager.ConnectionStrings["CFDConnectionString1"].ConnectionString; Conn = new SqlConnection(ConnString); if (!isMM) { string query = "INSERT INTO DisclosureFiles " + "(DisclosuerSummaryId, FileName, Contents, DocGUID, DateModified) " + "VALUES(@DisclosuerSummaryId, @FileName, @Contents, @DocGUID, @DateModified) "; cmdUploadDoc = new SqlCommand(); cmdUploadDoc.CommandType = CommandType.Text; cmdUploadDoc.Connection = Conn; cmdUploadDoc.CommandText = query; cmdUploadDoc.Parameters.Add("@DisclosuerSummaryId", SqlDbType.Int).Value = disclosureId; cmdUploadDoc.Parameters.Add("@FileName", SqlDbType.VarChar).Value = FileUpload1.PostedFile.FileName; cmdUploadDoc.Parameters.Add("@Contents", SqlDbType.VarBinary).Value = FileUpload1.FileBytes; cmdUploadDoc.Parameters.Add("@DocGUID", SqlDbType.UniqueIdentifier).Value = NewDOCGUID; cmdUploadDoc.Parameters.Add("@DateModified", SqlDbType.DateTime).Value = DateTime.Now; } else { string query = "INSERT INTO DisclosureFiles " + "(massMediaId, FileName, Contents, DocGUID, DateModified) " + "VALUES(@massMediaId, @FileName, @Contents, @DocGUID, @DateModified) "; cmdUploadDoc = new SqlCommand(); cmdUploadDoc.CommandType = CommandType.Text; cmdUploadDoc.Connection = Conn; cmdUploadDoc.CommandText = query; cmdUploadDoc.Parameters.Add("@massMediaId", SqlDbType.Int).Value = disclosureId; cmdUploadDoc.Parameters.Add("@FileName", SqlDbType.VarChar).Value = FileUpload1.PostedFile.FileName; cmdUploadDoc.Parameters.Add("@Contents", SqlDbType.VarBinary).Value = FileUpload1.FileBytes; cmdUploadDoc.Parameters.Add("@DocGUID", SqlDbType.UniqueIdentifier).Value = NewDOCGUID; cmdUploadDoc.Parameters.Add("@DateModified", SqlDbType.DateTime).Value = DateTime.Now; } Conn.Open(); int result = cmdUploadDoc.ExecuteNonQuery(); //this is where it crashes Conn.Close(); if (result &gt; 0) { lblMessage.Text = "File Saved Successfully"; } } else { lblMessage.Text = "Please Select a File to Upload"; } } catch (Exception ex) { lblMessage.Text = "Please report the following error: " + ex.Message; } finally { Conn.Close(); } </code></pre> <h2>}</h2> <p>Exception</p> <p>System.Data.SqlClient.SqlException: String or binary data would be truncated. The statement has been terminated. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at TestForm.btnSave_Click(Object sender, EventArgs e) in c:\inetpub\wwwdev\UploadPdf.aspx.cs:line 104 </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload