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...
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...