简体   繁体   English

SQL Server存储过程与外部dll

[英]SQL Server stored procedure vs an external dll

I am trying to convince someone that using an external DLL to manage sql data is better then using stored procedures. 我试图说服某人,使用外部DLL管理sql数据比使用存储过程更好。 Currently the person I am working with is using vba and calls sql stored procedures to get the complicated data they need from many different sources. 目前,我正在与之打交道的人正在使用vba,并调用sql存储过程以从许多不同的来源获取所需的复杂数据。 It is my understanding that the best way to go about this kind of action is to use a dll/ some intermediate layer to get the data and be able to format it to the needs. 据我了解,执行此类操作的最佳方法是使用dll /中间层来获取数据并能够将其格式化为需要的格式。

Some things to keep in mind: 注意事项:

  • The person i am working with doesn't care to much about being able to scale to much further then we are now 我正在与之共事的人并不关心能够扩展到更大范围,而现在我们
  • They don't care to be able to switch to different platforms 他们不在乎能够切换到不同的平台
  • They don't see to much of a performance problem with the current setup 他们认为目前的设置没有太大的性能问题
  • Using a dll requires more work that is in a different direction 使用dll需要做更多不同方向的工作
  • They don't want to switch if there's not a current problem with doing it the way it is now.(So just because its not the right way wont work...I tried) 如果当前的操作方式没有当前问题,他们不想切换(所以只是因为它的正确方式行不通...我尝试过)

So can anyone tell me some benefits of using an external dll then using sql stored procedures ? 那么谁能告诉我使用外部dll然后使用sql存储过程的一些好处?

Use stored procedures, and write your data access layer which calls them via parameterized commands in a separate dll. 使用存储过程,并编写数据访问层,该数据访问层通过参数化的命令在单独的dll中调用它们。 Stored procedures are a standard and give you a ton of benefits, parameterized commands give you automatic string safety. 存储过程是标准操作,可为您带来很多好处,参数化命令可为您提供自动的字符串安全性。

This type of design is basically so standardized and has been for years now that Microsoft has included a framework that constructs it for you in .NET 4. 这种类型的设计基本上已经标准化,并且已经使用了多年,以至于Microsoft在.NET 4中包含了一个为您构造它的框架。

More or less, both you and this other fellow are right, use sprocs for security, and separate your DAL for security and reusability and lots of reasons 或多或少,您和另一个伙伴都是正确的,使用sprocs来确保安全,并出于安全性和可重用性而将您的DAL分开,原因很多

ORM/DLL Approach ORM / DLL方法

Pro: 优点:

  • You don't have to learn SQL, or stored procedure syntax 您不必学习SQL或存储过程语法

Con: 缺点:

  • Complicates multiple operations in a single transaction 在单个事务中使多个操作复杂化
  • Risks increasing trips between the application and the database, which means data sync/concurrency issues 冒着增加应用程序与数据库之间旅行的风险,这意味着数据同步/并发问题
  • Utterly fails at complex queries; 在复杂的查询中完全失败; most support stored procedures via ORM because of this 因此,大多数通过ORM支持存储过程

You can save SQL, including stored procedures, in flat files. 您可以将SQL(包括存储过程)保存在平面文件中。 The file extension could be txt, but most use sql - makes storing SQL source in CVS/etc moot vs .NET or Java source code. 文件扩展名可以是txt,但是大多数使用sql-可以将SQL源代码存储在CVS / etc中,而不是.NET或Java源代码。

Agree with the points about controlling the code, much easier in a DLL. 同意有关控制代码的要点,在DLL中要容易得多。 Same with source control. 与源代码管理相同。 However, from a pure performance perspective, the stored procedures will win they day because they are compiled, not just cached. 但是,从纯粹的性能角度来看,存储过程将胜出,因为它们是经过编译的,而不仅仅是缓存的。 I don't know if it will make enough difference but thought I'd throw that in. 我不知道这是否会带来足够的改变,但我想我会考虑一下。

Using stored procedures can also be much more secure as you can lock down access to only stored procedures and you don't (have to) expose your table data to anyone with a connection. 使用存储过程也可以更加安全,因为您可以仅锁定对存储过程的访问,而不必(不必)向有连接的任何人公开表数据。

I guess I'm not really answering your question as much as pointing out holes in your argument. 我想我没有真正回答您的问题,还没有指出您的论点中的漏洞。 Sorry about that but I'm looking at it from their perspective. 抱歉,但是我从他们的角度来看。

I really think it comes down to a matter of preference . 我真的认为这归结为偏好问题 Personally I like ORM & saved queries in a DLL vs. Stored Procs, I find them much easier to maintain and distribute than deploying S.Procs to a DB. 我个人比较喜欢ORM和将查询保存在DLL与存储的Procs中,与将S.Procs部署到数据库相比,我发现它们更易于维护和分发。 There are some certain advantages that a S.Proc has over a raw query though. 与原始查询相比,S.Proc具有某些优势。 Some optimizations, and some server-side logic that could improve performance in some areas. 一些优化和一些服务器端逻辑可以提高某些方面的性能。

All In all though, personally I prefer to work in code than in DB mumbo-jumbo so that's really why I opt for the DLL approach. 总而言之,我个人更喜欢在代码中工作,而不是在DB Mumbo-jumbo中工作,因此,这就是为什么我选择DLL方法的原因。

Plus you can keep your source code in source-control too, much harder to do with a stored-proc. 另外,您也可以将源代码也保留在源代码控制中,而使用存储过程则要困难得多。

Just my 2c. 只是我的2c。

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

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