将大二进制数据保存到sql DB与C# [英] Save large binary data into sql DB with C#

查看:168
本文介绍了将大二进制数据保存到sql DB与C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个代码使用C#存储(最终大的)文件到DB。

I need a code to store (eventually large) files into DB using C#.

我使用的解决方案是sth like:
'm使用数据库中的varbinary(MAX)列)

The solution I'm using is sth like: (I'm using varbinary(MAX) column in the DB)

1)创建SqlCommand

1) Create SqlCommand

2)创建SqlParameter

2) Create SqlParameter

3)设置parameter.Value = File.ReadAllBytes(filePath)

3) Set parameter.Value = File.ReadAllBytes(filePath)

4)执行SqlCommand

4) Execute SqlCommand

有没有更有效的解决方案?由于文件可能很大,当读取所有字节到内存中,然后将它们存储到DB时,我会担心性能问题。

Is there any more effective solution? Since the file can be large, I'm affraid of performance problems, when reading all bytes into memory, and then storing them into DB.

提前感谢您


Thank you in advance

推荐答案

您可以使用 varbinary(MAX)列。虽然您可以在数据库中流式传输数据,但在 中无法流式传输。

What you have is the best you can get with a varbinary(MAX) column. While you can stream data out of the database, there's no way to stream it in.

这篇关于将大二进制数据保存到sql DB与C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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