对于asp.net mvc Web应用程序,哪种方法可以将文本文件存储到Sql Server数据库中?

时间:2021-12-16 20:09:03

I'm making a small asp.net mvc app. in which I have to compute data from several CSV files ( between 5 to 10 files).

我正在制作一个小的asp.net mvc应用程序。我必须从几个CSV文件(5到10个文件之间)计算数据。

The application must provide upload and download actions for these files.

应用程序必须为这些文件提供上载和下载操作。

The part where I don't have experience is the data base. What column type should I use? text, image, binary ? the size of a file will be betweent 80KB to 500KB

我没有经验的部分是数据库。我应该使用哪种列类型?文字,图像,二进制?文件的大小将在80KB到500KB之间

1 个解决方案

#1


13  

The types TEXT, NTEXT and IMAGE are obsolete - do not use them for new development. They will be removed from a future SQL Server version for good.

TEXT,NTEXT和IMAGE类型已经过时 - 不要将它们用于新开发。它们将从未来的SQL Server版本中删除。

For SQL Server 2005 and up, use VARCHAR(MAX) / NVARCHAR(MAX) if you're dealing with pure text files (like source code or CSV files), or VARBINARY(MAX) if you're dealing with binary files.

对于SQL Server 2005及更高版本,如果要处理纯文本文件(如源代码或CSV文件),则使用VARCHAR(MAX)/ NVARCHAR(MAX);如果处理二进制文件,则使用VARBINARY(MAX)。

Those allow up to 2 GB of storage for each single file, and you can use all the usual T-SQL string functions on them to manipulate them (the (N)VARCHAR(MAX) fields, that is).

对于每个文件,这些允许最多2 GB的存储空间,并且您可以使用它们上的所有常用T-SQL字符串函数来操作它们(即(N)VARCHAR(MAX)字段)。

If you're using SQL Server 2008, there's also an additional option - the FILESTREAM attribute on VARBINARY(MAX) columns. This allows you to store the files in the SQL Server machine's file system (instead of the database tables) while preserving transactional and data integrity.

如果您使用的是SQL Server 2008,还有一个附加选项 - VARBINARY(MAX)列上的FILESTREAM属性。这允许您将文件存储在SQL Server计算机的文件系统(而不是数据库表)中,同时保留事务和数据完整性。

FILESTREAM is recommended for files that are typically and usually larger than 1 MB in size, or if you ever need more than 2 GB (since you can't store more than 2 GB in a regular VARBINARY(MAX) column).

对于通常且通常大于1 MB的文件,或者如果您需要超过2 GB(因为在常规VARBINARY(MAX)列中不能存储超过2 GB),建议使用FILESTREAM。

Marc

渣子

#1


13  

The types TEXT, NTEXT and IMAGE are obsolete - do not use them for new development. They will be removed from a future SQL Server version for good.

TEXT,NTEXT和IMAGE类型已经过时 - 不要将它们用于新开发。它们将从未来的SQL Server版本中删除。

For SQL Server 2005 and up, use VARCHAR(MAX) / NVARCHAR(MAX) if you're dealing with pure text files (like source code or CSV files), or VARBINARY(MAX) if you're dealing with binary files.

对于SQL Server 2005及更高版本,如果要处理纯文本文件(如源代码或CSV文件),则使用VARCHAR(MAX)/ NVARCHAR(MAX);如果处理二进制文件,则使用VARBINARY(MAX)。

Those allow up to 2 GB of storage for each single file, and you can use all the usual T-SQL string functions on them to manipulate them (the (N)VARCHAR(MAX) fields, that is).

对于每个文件,这些允许最多2 GB的存储空间,并且您可以使用它们上的所有常用T-SQL字符串函数来操作它们(即(N)VARCHAR(MAX)字段)。

If you're using SQL Server 2008, there's also an additional option - the FILESTREAM attribute on VARBINARY(MAX) columns. This allows you to store the files in the SQL Server machine's file system (instead of the database tables) while preserving transactional and data integrity.

如果您使用的是SQL Server 2008,还有一个附加选项 - VARBINARY(MAX)列上的FILESTREAM属性。这允许您将文件存储在SQL Server计算机的文件系统(而不是数据库表)中,同时保留事务和数据完整性。

FILESTREAM is recommended for files that are typically and usually larger than 1 MB in size, or if you ever need more than 2 GB (since you can't store more than 2 GB in a regular VARBINARY(MAX) column).

对于通常且通常大于1 MB的文件,或者如果您需要超过2 GB(因为在常规VARBINARY(MAX)列中不能存储超过2 GB),建议使用FILESTREAM。

Marc

渣子