如何在DLL中处理数据库依赖? [英] How to handle database dependencies in a dll?

查看:72
本文介绍了如何在DLL中处理数据库依赖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个关于如何处理'通用'dll中的数据库依赖关系的问题。



例如,我编写了一个将异常信息记录到数据库的DLL。我们希望为多个客户使用此功能。

现在我们假设我已经为客户A使用了此功能,并且同事已将其用于客户B.第一个设置很简单。运行数据库脚本并在代码中使用dll。然后dll将写入数据库。



现在对于客户A我对数据库模式进行了一些更改,假设我记录了一些额外的信息。现在,当我的同事去为客户B工作时(可能是在我做出更改后几个月!)他的软件会崩溃,因为新列不在他的数据库中。在最糟糕的情况下,他忘记更新客户B的数据库,代码将在生产中崩溃(对我的同事感到羞耻,但他可能根本不知道任何数据库更改)。



处理这个问题的好方法是什么?

我应该有dll的版本1的数据库脚本,dll的版本2(如果它还包括版本1)还没有安装)等等。

我应该检查一个表和记录,指明数据库中dll的用法和版本,并在不存在时显示错误吗?

是否有某种工具可以使用相应的数据库脚本轻松保存dll的单独版本?



有没有人有一个很好的解决方案是否需要dll的每个用户都知道数据库脚本和更改?

也许是内置解决方案,可编程解决方案或第三方解决方案?



我正在使用的数据库是SQL Server 2005和hi gher和软件是Visual Studio 2010中的.NET4(包括VB和C#)(我们很快就会切换到更新的版本)。



谢谢。

Hi all,
I have a question about how to handle database dependencies in 'generic' dll's.

For example, I have written a dll that logs exception information to a database. We want to use this functionality for multiple customers.
Now let's assume I have used this functionality for customer A and a colleague has used it for customer B. The first setup is easy. Run a database script and use the dll in your code. The dll will then write to the database.

Now for customer A I make some changes to the database schema, let's say I log some extra information. Now when my colleague goes to work for customer B (perhaps a few months after I made the changes!) his software will crash because the new columns are not in his database. In a worst case scenario he forgets to update the database of customer B and the code will crash in production (shame on my colleague, but he may not be aware of any database changes at all).

What is a good way to handle this?
Should I have a database script for version 1 of the dll, version 2 of the dll (that also includes version 1 if it is not yet installed) etc.
Should I check if a table and record specifying the use and version of the dll in the database and show an error when it is not present?
Is there some kind of tool that can easily keep seperate versions of the dll with the corresponding database scripts?

Does anyone have a good solution for this that doesn't require every user of the dll to be aware of database scripts and changes?
Perhaps built-in solutions, programmable solutions or third-party solutions?

The database(s) I'm using are SQL Server 2005 and higher and the software is .NET4 (both VB and C#) in Visual Studio 2010 (we might switch to a newer version soon).

Thanks.

推荐答案

您所谈论的是软件版本控制,它是一个非常大的主题 - 发布管理的一部分。可以写关于这个区域的整本书。



所以,最大的问题是,有没有简单的方法来实现这一目标?答案是肯定的,但它要求您从一开始就在DLL中放置相当多的基础设施。您需要的第一件事是记录您的DLL当前在数据库中的版本。一个简单的表通常就足够了,包含一个包含该版本的字符串。当你的DLL被调用时,它的第一件事就是检查数据库中的版本是什么。如果该版本低于当前版本,那么您需要应用脚本以正确的顺序更新数据库。



幸运的是,实际上编写此基础结构并非如此那很复杂。
What you are talking about is software versioning, and it's part of a very big topic - release management. Whole books can be written about this area.

So, the big question is, are there any simplistic ways of achieving this? The answer is yes, but it requires you to put quite a bit of infrastructure in place in your DLL right from the start. The first thing you need is a way of recording what version your DLL is currently at in the database. A simple table will usually suffice here consisting of a string containing the version. When your DLL is invoked, the first thing any method in it has to do is check to see what the version is in the database. If that version is less than the current version, then you need to apply your scripts to update the database in the correct order.

Fortunately, actually writing this infrastructure isn't that complicated.


这篇关于如何在DLL中处理数据库依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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