简体   繁体   English

自定义ADO.NET提供程序来拦截和修改sql查询

[英]Custom ADO.NET provider to intercept and modify sql queries

Our client has an application that stores blobs in database which has now grown enough to impact the performance of SQL Server. 我们的客户端有一个应用程序,它将blob存储在数据库中,现在已经增长到足以影响SQL Server的性能。 To overcome this issue, we are planning to offload all blobs to file system and leave the path of file in a new column in user table. 为了解决这个问题,我们计划将所有blob卸载到文件系统,并将文件路径保留在用户表的新列中。

Like if user has a table docs with columns id, name and content (blob); 就像用户有一个包含列id,名称和内容(blob)的表文档; we would ask him to add a new column 'filepath' in this table. 我们会要求他在此表中添加一个新列'filepath'。

Our client is willing to make this change in this database. 我们的客户愿意在此数据库中进行此更改。 But when it comes to changing the sql queries to read and write into this table, they are not ready to accep this. 但是,当涉及到更改sql查询以读取和写入此表时,他们还没有准备接受这个。 Actually, they don't want any change that results in recompilation and deployment. 实际上,他们不希望任何导致重新编译和部署的更改。

Now we are planning to write a custom ADO.NET provider that will 现在我们计划编写一个自定义的ADO.NET提供程序

  • intercept the select queries 拦截选择的查询
  • add a column 'filepath' at the end of the select statement 在select语句的末尾添加一个列'filepath'
  • retieve the result set and modify the 'content' column value based on 'filepath' value 撤消结果集并根据“filepath”值修改“content”列值

Is there any use case that you think will certainly fail with this approach? 是否有任何用例你认为这种方法肯定会失败?

I know this sounds dirty but do we have a better way? 我知道这听起来很脏但我们有更好的方法吗?

Have you tried switching the column to the FILESTREAM data type? 您是否尝试将列切换为FILESTREAM数据类型? This does everything you describe, pushing the data out of the database (onto the file-system). 这将完成您描述的所有操作,将数据数据库中推出(到文件系统中)。 Of course, access still needs to go though the server as TDS, but you may find the impact is less, and you can progressively change code to access the file more directly (for improved performance) - this last step would involve altering queries, however. 当然,访问仍然需要通过服务器作为TDS,但您可能会发现影响较小,并且您可以逐步更改代码以更直接地访问文件(以提高性能) - 最后一步涉及更改查询,但是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM