擅长存储在SQL Server中的文件 [英] Store excel file in SQL Server

查看:90
本文介绍了擅长存储在SQL Server中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找的这种情况下很好的解决方案:

I'm looking for a good solution for this scenario:


  • 我与SQL Server 2008 R2后端的asp.net应用程序。

  • 我需要让用户上传文件,并保存供以后检索。

  • 此外,我需要解析该文件对数据库查询方的目的。所以,我需要从这个文件中同时数据的数据表,并从SQL到的结果结合起来。

因此​​,这里就是我想的:

So here's what I thought of:


  1. 存储擅长在SQL Server文件 VARBINARY(最大) - 这将使后来通过.NET pretty容易
  2. 来检索文件。
  3. 解析:这样做的一个方法是在文件上传用户与OPENXML或一些第三方库到的数据表分析它,并把它传递给存储过程将返回结果集

  1. Store excel file in SQL Server as varbinary(max) - this will allow to retrieve file later through .net pretty easy.
  2. Parsing: one way to do it is upon file uploading by user parse it with openxml or some 3rd party library into datatable and pass it to stored procedure which will return resultset.

我不喜欢这种做法,因为这意味着我们将不得不通过整个文件时,数据量显著传递到数据库两次(第一次,第二次和传递一个数据集时。

I don't like this approach, because it means that we will have to pass significant amount of data to the database two times (First when passing the whole file, and 2nd when passing a dataset.

这是如何更有效地做到这一点有什么建议?是否有可能使用这样的事情来读取VARBINARY最大数据:

Any suggestions on how to do this more efficiently? Is it possible to read data from varbinary max using something like this:

SELECT *
FROM OPENDATASOURCE('Microsoft.ACE.OLEDB.12.0', 
                    'Data Source=D:\TestJET.xls;
                    Extended Properties=''Excel 12.0;HDR=NO;IMEX=1;ImportMixedTypes=Text''')...[Sheet1$]

但没有实际创建文件?

but without actually creating a file?

或者,也许有可能不通过整个文件的分贝,而构建的Excel数据表,从文件回来?

Or maybe it is possible not to pass the whole file to the db, but construct excel file back from datatable?

也许 VARBINARY(最大)不是最佳的解决方案,更好地使用不同的数据类型,如XML?

Or maybe varbinary(max) is not the best solution and better use different datatype like XML?

Excel文件pretty简单。一个风格的表,没有宏或公式。 (不能转换为CSV虽然)文件大小200-800kb。

Excel file is pretty simple. One styled table with no macros or formulas. (Cannot be converted to CSV though) file size is 200-800kb.

推荐答案

您构建从DB Excel文件的想法是有趣的 - 这表明它得到的相同文件恢复这并不重要上传,只是一个包含相同的信息的。这是否正确?

Your idea of constructing the excel file from the DB is interesting - this suggests that it's not important to get the same file back that was uploaded, just one that contains the same information. Is that correct?

如果是这样,我会分析在上载的文件(我喜欢 ClosedXML 以C#擅长的工作)在服务器上,保存在一个查询友好的形式相关的数据在数据库中,然后抛出原来的文件了。当用户要求文件回来,为他们创造一个新的与正确的内容。

If so, I would parse the file on upload (I like ClosedXML for C# excel work) on the server, store the relevant data in a query-friendly form in your database and then throw the original file away. When the user asks for the file back, create a new one for them with the right contents.

请小心使用XML数据类型列 - 他们拥有的限制你可以与他们做什么的。

Be careful with XML Data type columns - they have restrictions on what you can do with them.

这篇关于擅长存储在SQL Server中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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