Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server vb.net中的内存不足_Sql Server_Vb.net_Image_Out Of Memory_Varbinarymax - Fatal编程技术网

Sql server vb.net中的内存不足

Sql server vb.net中的内存不足,sql-server,vb.net,image,out-of-memory,varbinarymax,Sql Server,Vb.net,Image,Out Of Memory,Varbinarymax,我正在从数据库中插入和检索图像。我现在可以插入,但检索文件时遇到困难。我使用varbinary(max)作为图像的数据类型 这是我插入的代码: Dim ms作为新的内存流 PictureBox1.Image.Save(ms,PictureBox1.Image.RawFormat) Dim img()作为字节 img=ToArray女士() cmd.CommandText=“插入螺柱值(”&studno.Text&“,”&password.Text&“,”&fname.Text&“,”&mname

我正在从数据库中插入和检索图像。我现在可以插入,但检索文件时遇到困难。我使用varbinary(max)作为图像的数据类型

这是我插入的代码:

Dim ms作为新的内存流
PictureBox1.Image.Save(ms,PictureBox1.Image.RawFormat)
Dim img()作为字节
img=ToArray女士()
cmd.CommandText=“插入螺柱值(”&studno.Text&“,”&password.Text&“,”&fname.Text&“,”&mname.Text&“,”&lname.Text&“,@img,”&gender.Text&“,”&mm.Text&“/”&dd.Text&“/”&yyyyy.Text&“,“&phone.Text&“,”,“&address.Text&“,”学生“,“&secquest.Text&“,”,&answersq.Text&“,”&TextBox1.Text&“,”&ComboBox1.Text&“)”
cmd.Parameters.Add(“@img”,SqlDbType.VarBinary).Value=img
这就是我检索的方式:

con.Open()
cmd.CommandText=“从studentno='mnb'的螺柱中选择*
cmd.Connection=con
dr=cmd.ExecuteReader()
而里德博士
studnum.Text=dr.Item(“studentno”)
fname.Text=dr.Item(“fname”)
mname.Text=dr.Item(“mname”)
lname.Text=dr.Item(“lname”)
性别。文本=博士项目(“性别”)
section.Text=dr.Item(“seccode”)
bday.Text=dr.Item(“bday”)
phone.Text=dr.Item(“phoneno”)
address.Text=dr.Item(“maddress”)
Dim imageData作为字节()=直接广播(dr(“pic”),字节()
如果没有,那么imageData什么都不是
将ms用作新内存流(imageData,0,imageData.Length)
ms.Write(imageData,0,imageData.Length)
PictureBox1.BackgroundImage=Image.FromStream(毫秒,真)
终端使用
如果结束
结束时
我的问题是,每当我运行我的程序时,它都会显示内存不足。如何解决?我正在检索的图像大小为2MB


我正在使用memorystream和我研究过的最常用的文件流。我相信这在某些方面是不同的。

错误是由于memoryStream应该一直处于打开状态

要解决此问题,请使用以下函数从字节数组获取图像

    Public Function byteArrayToImage(byteArrayIn As Byte()) As Image
        Dim img As Image = Nothing           
            Dim ms As New MemoryStream(byteArrayIn, 0, byteArrayIn.Length)
            ms.Write(byteArrayIn, 0, byteArrayIn.Length)
            img = Image.FromStream(ms, True)             
        Return img
    End Function
调用函数填充PictureBox1:

  PictureBox1.Image = byteArrayToImage(imageData)

尝试将字节数组转换为图像:

公共函数byteArrayToImage(byteArrayIn作为Byte())作为图像
将mStream用作新内存流(byteArrayIn)
返回Image.FromStream(mStream)
终端使用
端函数

一个大图像的可能副本,考虑将图像存档到某处,只保存文件名。您的读卡器设置为在循环中读取,这意味着您可以创建多个图像-前面的图像都不会被处理,只需在您的内存中添加几个RAM条即可box@GSerg我相信没有。不幸的是,该线程没有帮助我解决问题。实际上,当我这样做时,我会将文件存储到AppData文件夹中,在名称前加上一些内容(如PK),然后只保存文件名。可以将路径位置添加回以加载文件,这样您就可以在不破坏任何内容的情况下移动images文件夹。