我有很多大小超过 1 MB 的图像,我需要将它们保存在 MySQL 中。有时它可以更新 1 mb 大小的图像,但有时甚至无法保存 500 kb 的图像。
我已经在 MySQL Server 5.0 的 my.ini 文件中将 max_allowed_packet 更改为 32M。
这是我保存图像的代码。我在这里做错了什么吗?
Try
Dim FileSize As UInt32
Dim mstream As New System.IO.MemoryStream()
pic_box_save.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim arrImage() As Byte = mstream.GetBuffer()
FileSize = mstream.Length
mstream.Close()
' MsgBox(FileSize)
MyConnection()
Sql = "update AREA set AREA_NAME=@Aname, AREA_IMG=@image_data where AREA_NO='" & cboAreaNo.Text & "'"
Dim cmd As New MySqlCommand(Sql, Con)
cmd.Parameters.AddWithValue("@Aname", txtAreaname.Text)
cmd.Parameters.AddWithValue("@image_data", arrImage)
cmd.ExecuteNonQuery()
MsgBox("Data successfully updated!!", vbInformation, "Updating")
Con.Close()
Catch ex As Exception
MsgBox("Data not Saved!!!" + ex.Message, vbCritical, "System message")
End Try
最佳答案
我只需要添加
SET GLOBAL max_allowed_packet=32*1024*1024
关于mysql - 无法在 MySQL 中保存大图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31633223/