473,654 Members | 3,035 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.Net Abysmal File Uploads (to Database)

I am using Visual Studio.Net 2003, Visual Basic, Dot-Net 1.1
framework.

I have a function to upload files into a database, which worked great
when I was developing my application, but got slow and eventually died
after I had uploaded a few hundred files into my database.

The error in the event viewer was:
"aspnet_wp. exe (PID: 6952) was recycled because memory consumption
exceeded the 613 MB (60 percent of available RAM)."

Using Task manager, I watched as the aspnet_wp process hiked from
around 25 MB up to 600+ MB and crashed. Since I didn't seem to have
any loop problems, nested function calls, and the like, I was pretty
perplexed

Public Function File_Upload(ByR ef HTML_Upload_Con trol As
HtmlInputFile) As Integer
Dim sqlstring As String
Dim SQLAdapterObjec t As SqlDataAdapter
Dim SQLDataSetObjec t As DataSet
Dim SQLCommandBuild erObject As SqlCommandBuild er

Dim RecordID As Integer
Dim File_Name As String
Dim File_Size As Integer
Dim File_MimeType As String

File_Name = HTML_Upload_Con trol.PostedFile .FileName
File_Name = File_Name.Subst ring(File_Name. LastIndexOf("\" ) +
1)
File_Size = HTML_Upload_Con trol.PostedFile .ContentLength
File_MimeType = HTML_Upload_Con trol.PostedFile .ContentType
Dim File_Binary(Fil e_Size) As Byte
HTML_Upload_Con trol.PostedFile .InputStream.Re ad(File_Binary,
0, File_Size)

sqlstring = "SELECT * FROM [File_Store] ORDER BY RecordID
DESC"
SQLDataSetObjec t = New DataSet
SQLAdapterObjec t = New SqlDataAdapter( sqlstring,
SQLConnectionOb ject)
SQLCommandBuild erObject = New
SqlCommandBuild er(SQLAdapterOb ject)
SQLAdapterObjec t.Fill(SQLDataS etObject, "Table")
Try
Dim SQLNewRow As DataRow
SQLNewRow = SQLDataSetObjec t.Tables("Table ").NewRow()
SQLNewRow("File _Name") = File_Name
SQLNewRow("File _MimeType") = File_MimeType
SQLNewRow("File _Size") = File_Size
SQLNewRow("File _Binary") = File_Binary
SQLDataSetObjec t.Tables("Table ").Rows.Add(SQL NewRow)
SQLAdapterObjec t.Update(SQLDat aSetObject, "Table")
Catch ex As Exception
End Try

sqlstring = "SELECT Max(RecordID) as File_ID from
[File_Store];"
OpenQuery(sqlst ring)
If SQLDataReaderOb ject.Read() Then
RecordID = getInteger(SQLD ataReaderObject ("File_ID"))
Else
RecordID = 0
End If
CloseQuery()

Return RecordID
End Function

I managed to correct the symptoms by replacing this one line of code:

sqlstring = "SELECT TOP 1 * FROM [File_Store] ORDER BY
RecordID DESC"

Apparently, before I even iterate through the dataset or the
dataadapter, the entire contents of the [file_store] table is being
sent to my server. I had originally believed that this statement only
retrieved the schema of the table, until I actually iterated through
the data. This is not the case, apparently.

My solution, obviously, isn't ideal, because I'm still downloading a
file that I don't need. I tried putting a condition that would NEVER
return a file, but... new files didn't upload if my DataSet didn't
include at least one record from the query.

I hope this helps somebody, but if someone has a better way of solving
this type of problem, I would appreciate details.

Thanks,
Joshua

Apr 6 '07 #1
2 1299
DataSets are downloaded in a one shot. Essentially the schema and all data
returned by the query is loaded into the dataset.

Can you give some more understanding into the process involved, basic flow
or the like. In this case, seeing the exact how you're doing it isn't as
helpful as the why as we understand the problem you're facing, just not sure
if there is a better design choice that would go completely around this
issue.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

<jo************ *@oxy.comwrote in message
news:11******** *************@n 76g2000hsh.goog legroups.com...
>I am using Visual Studio.Net 2003, Visual Basic, Dot-Net 1.1
framework.

I have a function to upload files into a database, which worked great
when I was developing my application, but got slow and eventually died
after I had uploaded a few hundred files into my database.

The error in the event viewer was:
"aspnet_wp. exe (PID: 6952) was recycled because memory consumption
exceeded the 613 MB (60 percent of available RAM)."

Using Task manager, I watched as the aspnet_wp process hiked from
around 25 MB up to 600+ MB and crashed. Since I didn't seem to have
any loop problems, nested function calls, and the like, I was pretty
perplexed

Public Function File_Upload(ByR ef HTML_Upload_Con trol As
HtmlInputFile) As Integer
Dim sqlstring As String
Dim SQLAdapterObjec t As SqlDataAdapter
Dim SQLDataSetObjec t As DataSet
Dim SQLCommandBuild erObject As SqlCommandBuild er

Dim RecordID As Integer
Dim File_Name As String
Dim File_Size As Integer
Dim File_MimeType As String

File_Name = HTML_Upload_Con trol.PostedFile .FileName
File_Name = File_Name.Subst ring(File_Name. LastIndexOf("\" ) +
1)
File_Size = HTML_Upload_Con trol.PostedFile .ContentLength
File_MimeType = HTML_Upload_Con trol.PostedFile .ContentType
Dim File_Binary(Fil e_Size) As Byte
HTML_Upload_Con trol.PostedFile .InputStream.Re ad(File_Binary,
0, File_Size)

sqlstring = "SELECT * FROM [File_Store] ORDER BY RecordID
DESC"
SQLDataSetObjec t = New DataSet
SQLAdapterObjec t = New SqlDataAdapter( sqlstring,
SQLConnectionOb ject)
SQLCommandBuild erObject = New
SqlCommandBuild er(SQLAdapterOb ject)
SQLAdapterObjec t.Fill(SQLDataS etObject, "Table")
Try
Dim SQLNewRow As DataRow
SQLNewRow = SQLDataSetObjec t.Tables("Table ").NewRow()
SQLNewRow("File _Name") = File_Name
SQLNewRow("File _MimeType") = File_MimeType
SQLNewRow("File _Size") = File_Size
SQLNewRow("File _Binary") = File_Binary
SQLDataSetObjec t.Tables("Table ").Rows.Add(SQL NewRow)
SQLAdapterObjec t.Update(SQLDat aSetObject, "Table")
Catch ex As Exception
End Try

sqlstring = "SELECT Max(RecordID) as File_ID from
[File_Store];"
OpenQuery(sqlst ring)
If SQLDataReaderOb ject.Read() Then
RecordID = getInteger(SQLD ataReaderObject ("File_ID"))
Else
RecordID = 0
End If
CloseQuery()

Return RecordID
End Function

I managed to correct the symptoms by replacing this one line of code:

sqlstring = "SELECT TOP 1 * FROM [File_Store] ORDER BY
RecordID DESC"

Apparently, before I even iterate through the dataset or the
dataadapter, the entire contents of the [file_store] table is being
sent to my server. I had originally believed that this statement only
retrieved the schema of the table, until I actually iterated through
the data. This is not the case, apparently.

My solution, obviously, isn't ideal, because I'm still downloading a
file that I don't need. I tried putting a condition that would NEVER
return a file, but... new files didn't upload if my DataSet didn't
include at least one record from the query.

I hope this helps somebody, but if someone has a better way of solving
this type of problem, I would appreciate details.

Thanks,
Joshua

Apr 6 '07 #2
Thanks for your response. I'm not sure that I understand your
question, though. I have a file upload control, and when the page
posts, I want a file to be saved into a database. I have no special
interest in a dataset or any other objects. The example I saw on a
website showed the code above (or a close approximation) as the way to
accomplish this. I would be happy to do it in any other way.

Apr 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2428
by: OneSolution | last post by:
Hi All, Here's one thing that I don't know much about - file uploading. As part of my project, I will have to build a file manager of sorts - perhaps a document manager. Anyhow, this involves allowing my user to upload files to a location. I know PHP can do it - I know this because it sure does everything else ... but I don't know this from any authoritative source.
1
1669
by: Doug Helm | last post by:
I should have been more clear in my subject line. I was also the poster in the "File Uploads" topic. I'm not having any luck getting file uploads to work (multi-part HTML form) on a Windows server. I'm using a very close approximation of public domain code that I found. I've tried a couple of different implementations (very similar), but I am essentially using the following test code: ...
5
1728
by: !!bogus | last post by:
Hi, I found this code in the MSDN library. It works fine for a single upload, but I can't figure out how to make it work for multiple file uploads...can someone please help me? Just paste it in an aspx file and it will work. Although I don't see the HtmlInputFile class or the fileupload.aspx class that it refers to, it somehow works.
4
4410
by: Mick | last post by:
Anyone know of any problems with this??? Using it to upload image files to a server. Most of the files work fine but occasionally one causes error with fopen() on server. Seems the 'filename/path' param is incorrect. It is actually trying to open the file using the directory path I uploaded 'from' and not 'to'. (Note: Using PHP on Novell server to open the file.) Thanks,
1
3524
by: Doug Helm | last post by:
Hey, Folks: I'm writing a CGI to handle very large file uploads. I would like to include a progress bar. I think I'm about done. I have code to handle the file upload, and I think I can add an IFrame to my page which posts to check file size (so I can tell how many bytes have been received). My problem is that I want to provide a % complete. In order to do that, of course, I need to know not only the number of bytes received, but...
4
340
by: Steven | last post by:
I have a situation where I need to upload more than one file from a client to the server, I am having problems finding any examples of how I can ahhieve my goal. My Requirements are: 1, There must be no user interaction 2, The files names need to be discovered at run time 3, I must be able to upload 1 or more files determinded by step to. I was to use ASP.NET and javascript client side. I can use COM and such like
4
3493
by: mcrose | last post by:
I've written theh standard applicaiton for our client to allow indexed (customer name, subject etc) file uploads via secure http using the <input type='file'http element. This works great, and has the added benefit over FTP that I can begin processing the file data stream while the download is in progress. Yeah. The client is happy, but now they want to upload multi GB files. The http request are limitted to something like 2 or 4 GB. I...
6
5097
by: Brybot | last post by:
I am trying to allow HTTP POST file uploads to my web service. Currently I have it working perfectly for a SOAP/XML request reading in a byte using MemoryStream/FileStream but I cannot figure out how to encode a file on a POST to the same web service. The definition requires a base64binary encoded file, which I have tried. The form is also using a mutlipart/form-data enctype, but I either get a 500 error or 'Request format is invalid'. ...
10
13133
by: Kal | last post by:
I recently installed Windows 2008 Server to replace a crashed hard drive on a web server with a variety of web pages including several classic ASP applications. One of these makes extensive use of file uploads using a com tool that has worked for several years. Under IIS7 doc files and jpeg files upload as before, but zip files give a 500 error. This works the same with the firewall on and off.
0
8376
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8708
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8489
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7307
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2716
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1596
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.