3

我正在尝试将 SQL2008 支持添加到 .NET 2.0 应用程序。但是,我唯一的限制是一些用户仍然会使用 SQL2005,我不想要求他们安装 SQL2008 客户端组件。

我需要的 SQL2008 的实际 DLL 集与 SQL2005 不同。代码可以保持不变。

底线,我需要在VS2005(或手动编辑汇编文件)中说:

如果用户有 DLL_1 v2、DLL_2 v2 和 DLL_3 v2,请使用它们。如果没有,请使用 DLL_1 v1 和 DLL_2 v1。


我将研究使用反射来加载 DLL,这听起来对我来说几乎是唯一的选择,而不是需要 SQL 2008 客户端组件。

至于重新分发 DLL,我确实阅读了许可证。那里有几个适用于我们的可疑术语(例如,对于托管软件)。另外,这是一个更加复杂的问题,因为我们的客户数据非常敏感,因此他们通过广泛的审批流程来允许安装任何东西,例如我们包含的 DLL。

谢谢您的帮助!


感谢您的想法!然而,我们还没有完全到那里......

  1. 不,用户没有选择他们要安装到哪个数据库版本。目的是允许 SQL2005 和/或 SQL2008,即使在同一个安装中。例如,我们有一个管理应用程序,允许用户跨不同的 SQL 服务器管理数据库实例。

  2. 我意识到我们可以添加一个对话框来选择是否需要 SQL2008 支持。但是,这会进一步扩展我们的测试矩阵,这是我们试图避免的。

  3. 我相信我确实需要直接引用 DLL。我对数据库做的不仅仅是连接和查询。

我需要的 DLL 是:

  • Microsoft.SqlServer.ConnectionInfo
  • Microsoft.SqlServer.Management.Sdk.Sfc
  • 微软.SqlServer.Smo
  • Microsoft.SqlServer.SmoExtended
  • Microsoft.SqlServer.SqlEnum

还有其他想法,想法吗?

4

6 回答 6

1

反射将允许您在运行时动态加载所需的 DLL 集。因此,您可以检测可用的内容并加载它。

唯一的缺点是使用反射会使您的工作更加困难和耗时。

于 2009-01-02T20:19:42.180 回答
0

If you're just doing basic data access, you shouldn't need to worry about it, either native client should work fine, and you can let the framework hook into it for you. If you specify the SQL client, .Net will use whichever one it can get its hands on. Are you using SMO Objects? In that case there could be some dependency issues.

于 2008-12-30T22:14:53.893 回答
0

用户是否选择要安装到哪个数据库版本?(我假设有某种安装过程)。您可以根据所选数据库版本在安装时换出 bin 文件夹中的 dll 文件吗?

于 2008-12-31T16:34:01.743 回答
0

您可以在代码中更改表适配器的连接字符串,那么是否有必要为 SQL2008 编写全新的 dll?

于 2008-12-30T16:35:42.440 回答
0

You shouldn't have to make a direct reference to any DLLs at all. If you are using System.Data.SqlClient to connect to your DBs then .Net will know how to talk to both of them. If you aren't using System.Data.SqlClient to communicate with your servers then the next question become can you switch over to that namespace for your DB communication.

This may be a little outside the realm of what you are looking to do, but you could create a service layer abstraction where everybody connects to the service layer and the service layer handles the routing and the communication with the DB servers and you can communicate with the service layer either via SOAP or .Net Remoting. I've started to switch all of my apps over to this method as it allows me to focus my business logic and db abstraction in one controlled location and working with the presentation on the local machine.

于 2008-12-31T16:08:31.887 回答
0

您可以使用服务容器并在配置文件中连接依赖项。它可能需要将依赖于任一组程序集的代码分离成单独的类和程序集。

IE。两个类库,一个用于 2005,一个用于 2008,两者都包含一组实现一组通用接口的类。然后,应用程序将只向服务容器请求实现其中一个通用接口的对象,并且应用程序配置文件将指示将使用哪个实现。

这种配置当然也可以在应用程序启动时在代码中完成。

这种方法还允许您做更多的事情,而不仅仅是使用一组不同的 dll。如果某些事情需要在 2005 年与 2008 年不同地完成,您可以在您的类库中实现这些差异,并且应用程序不会更明智。

于 2009-01-02T23:08:29.267 回答