Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQLDBType.Image problem

Status
Not open for further replies.

JasonDBurke

Programmer
Jun 20, 2001
54
0
0
US
Hi,
I'm uploading documents to a server using this type. Documents that fall under 4MB in size upload fine. Anything larger throws a Page Not Found Error. Here is the code I am using. Any help would be awesome! Thanks in advance, Jason.

string theFileName = Path.GetFileName(selectedFile.PostedFile.FileName);

Stream s = selectedFile.PostedFile.InputStream;

BinaryReader br = new BinaryReader(s);

int documentBufferSize = selectedFile.PostedFile.ContentLength;

byte[] document = new byte[documentBufferSize];

br.Read(document,0,documentBufferSize);

SqlCommand comInsertRecord = new SqlCommand("insert into " + theTableName + "(Document,UserName,DateSubmitted,DocumentType,filecomment,FileName,FileSize)Values(@Document,@UserName,@DateSubmitted,@DocumentType,@FileComment,@FileName,@FileSize)", connInsertRecord);

comInsertRecord.Parameters.Add("@Document",SqlDbType.Image).Value = document;
comInsertRecord.Parameters.Add("@DateSubmitted",SqlDbType.DateTime).Value = DateTime.Now.ToString();
comInsertRecord.Parameters.Add("@DocumentType",SqlDbType.NVarChar,80).Value = theDocType; comInsertRecord.Parameters.Add("@FileComment",SqlDbType.NVarChar,255).Value = theFileComment.ToString(); comInsertRecord.Parameters.Add("@UserName",SqlDbType.NVarChar,50).Value = theUserName.ToString();
comInsertRecord.Parameters.Add("@FileName",SqlDbType.NVarChar,80).Value = theFileName.ToString();
comInsertRecord.Parameters.Add("@FileSize",SqlDbType.BigInt).Value = theFileSize.ToString();

connInsertRecord.Open(); // Open the connection
comInsertRecord.ExecuteNonQuery(); // Execute the query
connInsertRecord.Close(); // Close the connection

s.Close();
br.Close();
 
The code seems to be Okay and I think the error is generated by the database table allocation.
Maybe your DBA find a solution.
-obislavu-
 
Agreed. Check the size restriction on that field in the DBMS.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top