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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tricky BLOB upload problem...

Status
Not open for further replies.

VisualGuy

Programmer
May 27, 2003
162
US
I'm attempting to upload large textfiles into a table that has an image field. This, for all intents and purposes, should work...and it does for smaller files. However, it fails for large files on the upload... I've found a couple of examples of how to do this on the web, but here is one of them.

If TextBox1.Text Is String.Empty Then
MessageBox.Show("Browse a bitmap")
Return
End If
' Read a bitmap contents in a stream
Dim fs As FileStream = New FileStream(curFileName, _
FileMode.OpenOrCreate, FileAccess.Read)
Dim rawData() As Byte = New Byte(fs.Length) {}
fs.Read(rawData, 0, System.Convert.ToInt32(fs.Length))
fs.Close()

' Construct a SQL string and a connection object
Dim sql As String = "SELECT * FROM BlobTable"
Dim conn As OleDbConnection = New OleDbConnection
conn.ConnectionString = ConnectionString
ConnectionString &= "integrated security=SSPI;"
ConnectionString &= "Data Source=MyDataSource_SQL;"
ConnectionString &= "persist security info=False;"
ConnectionString &= "Initial Catalog=MyDataBase;"
ConnectionString &= "provider = SQLOLEDB"
conn.ConnectionString = ConnectionString
' Open connection
If conn.State <> ConnectionState.Open Then
conn.Open()
End If
' Create a data adapter and data set
Dim adapter As OleDbDataAdapter = _
New OleDbDataAdapter(sql, conn)
Dim cmdBuilder As OleDbCommandBuilder = _
New OleDbCommandBuilder(adapter)
Dim ds As DataSet = New DataSet("BlobTable")
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

' Fill data adapter
adapter.Fill(ds, "BlobTable")

' Create a new row
Dim row As DataRow = ds.Tables("BlobTable").NewRow()
row("Field1") = 17
row("Field2") = 9
row("Blob") = rawData
' Add row to the collection
ds.Tables("BlobTable").Rows.Add(row)
' Save changes to the database
adapter.Update(ds, "BlobTable")
' Clean up connection
If conn Is Nothing Then
If conn.State = ConnectionState.Open Then
conn.Close()
End If
' Dispose connection
conn.Dispose()
End If
MessageBox.Show("Txt Saved")

...Now I can do this with large files. I even got a 26meg file through OK. However, when I tried a 62.5meg file it failed without explaination during the update:

adapter.Update(ds, "BlobTable")

...Is it perhaps timing out and not telling me. It just gives a standard "An unhandled exception of type 'System.Data.Oledb.OleDException' occurred in system.data.dll'" message without any other explaination. Based on the .ToInt32(fs.Length) code, I'm under the impression that I should be able to upload files up to 2Gig is size. What am I not getting? I would greatly appreciate any help with this...
 
My thoughts were that it wasn't handling a timeout issue. Therefore, I added the following code:

Dim conn As OleDbConnection = New OleDbConnection
conn.ConnectionString = ConnectionString
ConnectionString &= "integrated security=SSPI;"
ConnectionString &= "Data Source=SHOPPERS_SQL;"
ConnectionString &= "persist security info=False;"
ConnectionString &= "Initial Catalog=SHOPPERS1T;"
ConnectionString &= "provider = SQLOLEDB;"
ConnectionString &= "Connect Timeout=300;"
conn.ConnectionString = ConnectionString
' Open connection
If conn.State <> ConnectionState.Open Then
conn.Open()
End If

The added part is the "Connect Timeout=300;". However this didn't help either. It's strange that it only fails when I attempt to upload text files larger than 30meg. Has anyone heard of this problem before?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top