在bytearray中读取非常大的文件并上传到MSSQL [英] Read very large file in bytearray and upload to MSSQL

查看:89
本文介绍了在bytearray中读取非常大的文件并上传到MSSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我需要将一个大文件(600Mb +)上传到MSSQL中的BLOB字段

2005.


我的代码如下:


fs =新FileStream(sFilePath,FileMode.Open)

Dim ByteArray(fs。长度)作为字节

fs.Read(ByteArray,0,fs.Length)

fs.Close()


问题是当我用我的600Mb文件调暗bytearray时,

bytearray变得无效。

我认为bytearray只能接受一个整数作为维度。


由于MSSQL的限制是2Gb,我应该如何写一个大文件来支付
MSSQL。

还有另一种方法可以获得一个文件的整个bytearray将

放入MSSQL?


问候,

Sven Peeters

解决方案

" Icemokka" < ic ****** @ gmail.comschrieb





我需要上传一个大文件(600Mb +)到MSSQL中的BLOB字段

2005.


我的代码如下:


fs =新FileStream(sFilePath,FileMode.Open)

Dim ByteArray(fs.Length)As Byte

fs.Read(ByteArray,0,fs.Length)

fs.Close()



如本例所示,强烈建议切换Option Strict

上。通过禁用它,您没有指出文件可以是大于2GB的
。检查文件大小之前,如果它不是> 2GB,你可以

安全地将fs.Length的Long值returend转换为整数。


问题是当我用600Mb文件调暗bytearray时,

bytearray变得无效。

我认为bytearray只能接受一个整数作为维度。



600MB在整数范围内,所以这不是问题。

Integer.MaxValue是2GB。


请注意,dim / redim语句需要数组的上限,

所以请替换fs.length。 byCint(fs.length) - 1


由于MSSQL的限制是2Gb,我该如何写一个大文件来

MSSQL。

还有另一种方法可以将文件的整个bytearray放入MSSQL吗?



您当前的问题是将字节数组放入数据库还是将文件读取到字节数组中?
如果它是前者,请查看ADO.Net

组,因为它不是VB.Net语言相关的问题。我也不确定

你的问题是将一个600多MB的文件(最多2GB)存储到

数据库中,或者你是否还要存储2GB +那里。存储文件的链接

是唯一的解决方案(AFAIK)。

Armin




嗯,我认为很难相信你达到了b
2,147,483,647的uperlimit。 。是一个整数的最大大小.Net

如果一个字节数组等于2047 +兆字节或1.9

+千兆字节

Michel


" Icemokka" < ic ****** @ berllt的gmail.comschreef

新闻:9b ************************ ********** @ n20g2000 hsh.googlegroups.com ...





我需要将一个大文件(600Mb +)上传到MSSQL中的BLOB字段

2005.


我的代码如下所示:


fs =新FileStream(sFilePath,FileMode.Open)

Dim ByteArray(fs.Length)As Byte

fs.Read(ByteArray ,0,fs.Length)

fs.Close()


问题是当我用600Mb文件调暗bytearray时,

bytearray变得无效。

我认为bytearray只能接受一个整数作为维度。


由于MSSQL的限制是2Gb,如何我应该把一个大文件写入

MSSQL。

还有另一种方法可以将文件的整个bytearray放入MSSQL中吗? ?


问候,

Sven Peeters



查看此示例

http://support.microsoft .com / kb / 308042


如果它不起作用,你可能会达到另一个限制(系统

资源,超时? )


另一种解决方案是将文件保存在文件服务器上,只有
存储数据库中文件的密钥和路径
主要是SQL dba不喜欢这些数据库中的hughe blob字段。


HTH


Michel


" Icemokka" < ic ****** @ berllt的gmail.comschreef

新闻:9b ************************ ********** @ n20g2000 hsh.googlegroups.com ...





我需要将一个大文件(600Mb +)上传到MSSQL中的BLOB字段

2005.


我的代码如下所示:


fs =新FileStream(sFilePath,FileMode.Open)

Dim ByteArray(fs.Length)As Byte

fs.Read(ByteArray ,0,fs.Length)

fs.Close()


问题是当我用600Mb文件调暗bytearray时,

bytearray变得无效。

我认为bytearray只能接受一个整数作为维度。


由于MSSQL的限制是2Gb,如何我应该把一个大文件写入

MSSQL。

还有另一种方法可以将文件的整个bytearray放入MSSQL中吗? ?


问候,

Sven Peeters



Hi,

I''m need to upload a big file ( 600Mb+ ) to a BLOB field in MSSQL
2005.

My code looks like this :

fs = New FileStream(sFilePath, FileMode.Open)
Dim ByteArray(fs.Length) As Byte
fs.Read(ByteArray, 0, fs.Length)
fs.Close()

The problem is when I dim the bytearray with my 600Mb file, the
bytearray becomes invalid.
I think the bytearray can only accept an integer as dimension.

Since MSSQL''s limit is 2Gb, how should I then write a big file to
MSSQL.
Is there another method to get the whole bytearray of a file to put
into MSSQL?

Regards,
Sven Peeters

解决方案

"Icemokka" <ic******@gmail.comschrieb

Hi,

I''m need to upload a big file ( 600Mb+ ) to a BLOB field in MSSQL
2005.

My code looks like this :

fs = New FileStream(sFilePath, FileMode.Open)
Dim ByteArray(fs.Length) As Byte
fs.Read(ByteArray, 0, fs.Length)
fs.Close()

As this example shows, it is strongly recommended to switch Option Strict
On. By disabling it, you are not pointed to the fact that a file can be
larger than 2GB. Check the file size before, and if it''s not >2GB, you can
safely convert the Long value returend by fs.Length to an Integer.

The problem is when I dim the bytearray with my 600Mb file, the
bytearray becomes invalid.
I think the bytearray can only accept an integer as dimension.

600MB is within the range of an integer, so this is not the problem.
Integer.MaxValue is 2GB.

Be aware that the dim/redim statements expect the upper bound of the array,
so replace "fs.length" by "Cint(fs.length) - 1"

Since MSSQL''s limit is 2Gb, how should I then write a big file to
MSSQL.
Is there another method to get the whole bytearray of a file to put
into MSSQL?

Is your current problem getting the byte array into the database or reading
the file into the byte array? If it''s the former, have a look at the ADO.Net
group because it is not a VB.Net language related problem. I''m also not sure
whether your problem is to store a 600+ MB file (up to 2GB) into the
database or if you also want to store 2GB+ there. Storing a link to the file
was the only solution (AFAIK).
Armin



Well i think it is hard to believe that you reach the uperlimit of
2,147,483,647. wich is the maximum size of an integer in .Net
wich in the case of a byte array is equivalant to 2047 + megabytes or 1.9
+ gigabytes
Michel

"Icemokka" <ic******@gmail.comschreef in bericht
news:9b**********************************@n20g2000 hsh.googlegroups.com...

Hi,

I''m need to upload a big file ( 600Mb+ ) to a BLOB field in MSSQL
2005.

My code looks like this :

fs = New FileStream(sFilePath, FileMode.Open)
Dim ByteArray(fs.Length) As Byte
fs.Read(ByteArray, 0, fs.Length)
fs.Close()

The problem is when I dim the bytearray with my 600Mb file, the
bytearray becomes invalid.
I think the bytearray can only accept an integer as dimension.

Since MSSQL''s limit is 2Gb, how should I then write a big file to
MSSQL.
Is there another method to get the whole bytearray of a file to put
into MSSQL?

Regards,
Sven Peeters



see this example

http://support.microsoft.com/kb/308042

if it doesn`t work, you are probably hitting another limit ( system
resources , timeout ?? )

Another solution would be to save your file on a file server , and only
store the key and path to the file in the database
mostly SQL dba`s don`t like these hughe blob fields in there database .

HTH

Michel

"Icemokka" <ic******@gmail.comschreef in bericht
news:9b**********************************@n20g2000 hsh.googlegroups.com...

Hi,

I''m need to upload a big file ( 600Mb+ ) to a BLOB field in MSSQL
2005.

My code looks like this :

fs = New FileStream(sFilePath, FileMode.Open)
Dim ByteArray(fs.Length) As Byte
fs.Read(ByteArray, 0, fs.Length)
fs.Close()

The problem is when I dim the bytearray with my 600Mb file, the
bytearray becomes invalid.
I think the bytearray can only accept an integer as dimension.

Since MSSQL''s limit is 2Gb, how should I then write a big file to
MSSQL.
Is there another method to get the whole bytearray of a file to put
into MSSQL?

Regards,
Sven Peeters



这篇关于在bytearray中读取非常大的文件并上传到MSSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆