Delphi XE2数据库编程问题
我知道并且听说过有很多方法可以连接到 Delphi (XE2) 中的 dabatase 服务器:套接字、datasnap、webservices、远程数据模块 (¿?)、dbExpress 和其他第三方,如 UniDAC。我通常使用 UniDAC,但我想知道何时以及如何正确使用它们。显然DataSnap是Delphi的旗舰产品。我还没有找到回答这些问题的有用教程。那么对于 Win32 应用程序,考虑到安全性、灵活性和可扩展性,开发客户端应用程序的推荐选项是什么?
有没有办法让客户端 Win32 应用程序对数据库访问的更改透明?也就是说,如果我分发了 100 个客户端应用程序,并且我想更改数据库访问密码,则必须更新每个客户端应用程序将是一个问题。
是否建议为客户端应用程序建立与数据库的唯一连接?
我尝试测试 DBExpress(与 Delphi XE2 捆绑)和 AnyDAC 连接到我的远程 MySQL 数据库,但 VendorLibs 存在问题。有没有一种方便的方法来解决这个问题,而不必安装我想要测试的每个 RDBMS?
DBExpress 是免费的还是我必须付费才能使用更多功能?
有人可以推荐一些非常好的书籍来学习DataSnap、中间件应用程序等吗?
提前致谢。
I know and I've heard about there are many ways to connect to a dabatase server in Delphi (XE2): sockets, datasnap, webservices, remote data module (¿?), dbExpress, and other thrid-party like UniDAC. I generally use UniDAC, but I'd wanna know When and How to properly use them. Apparently DataSnap is the flagship in Delphi. I haven't found useful tutorials answering those questions. So for a Win32 app, which would be the recommended option to develop a client app considering: security, flexibility, and scalability?
Is there an any way to do transparent for client Win32 apps respect to a change in database access? That is, If I had 100 client apps distributed and I wanna change the password for database access, it would be a problem to have to update every client app.
Is it recommendable to have a sole connection to a database for client apps?
I've tried to test DBExpress (bundled with Delphi XE2) and AnyDAC to connect to my remote MySQL database but I have problems with VendorLibs. Is there a handy way to resolve this without to have to install every RDBMS that I wanna test?
Is DBExpress free or I must pay for more functionality?
Anyone may recommend very good books to learn about DataSnap, middleware apps, and so on?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有多个分布式客户端,您可能需要使用多层解决方案(例如 DataSnap 或 DataAbstract),其中在服务器端运行单个持久数据连接,并且每个客户端只需连接到该服务器应用程序即可请求数据。
DataSnap 提供多种不同的客户端/服务器连接解决方案:Socketed、REST 等,因此您可以确定最适合您的系统的方案。
DataAbstract 似乎是市场上最流行的多层数据应用程序解决方案之一(如果不是的话),我碰巧知道许多开发人员出于各种原因而信赖它(安全性是其中之一,易用性是另一个原因)。
我一直认为,如果您的客户端应用程序需要直接连接到数据库,那么您就错了!
如果您正在寻找有关 DataSnap 的更多信息,最近的 CodeRage 活动中有一些有趣的会议。您可以在 Embarcadero 的 CodeCentral 子网站 下载/观看任何这些会议(免费)。
至于书籍,您最好的选择始终是 Marco Cantú 的 Delphi 手册(特别是 XE 书籍,它仍然主要适用于 XE2 的 DataSnap)。
重要的是要记住,DataSnap 仅随 Delphi 的 Enterprise、Ultimate 和 Architect 版本一起提供...它在 Pro 或 Starter 中不可用!
尽管如此,您始终可以在自己的服务器层上使用 ODBC 连接到任何 ODBC 数据库(包括 MySQL、MSSQL、Oracle...甚至 MS Access,如果您想享受“来自过去的爆炸”),然后使用任何网络您喜欢的套接字解决方案(例如 Delphi [所有版本] 附带的 Indy 作为标准)将您的客户端应用程序链接到服务器层!查看 TADOConnection、TADOQuery 等。
希望您发现此信息有用!
If you have multiple distributed clients, you would want to use a Multi-tier solution (like DataSnap or DataAbstract) where there is a single persisted data connection running on the server-side, and each client simply connects to that server application in order to request data.
DataSnap provides multiple different client/server connectiviy solutions: Socketed, REST etc. so it's up to you to determine what's best for your system(s).
DataAbstract appears to be one of (if not THE) most popular multi-tier data application solutions on the market, and I happen to know many developers swear by it for various reasons (security being one of them, ease of use being another).
I've always maintained that if your client application requires a direct connection to the database, you're doing it wrong!
If you're looking for more information on DataSnap, there were some interesting sessions on it at the recent CodeRage event. You can download/watch any of those sessions (freely) at Embarcadero's CodeCentral subsite.
As for Books, well your best bet will always be Marco Cantú's Delphi Handbooks (specifically the XE book, which still largely applies in terms of DataSnap for XE2).
It's important to keep in mind that DataSnap only ships with the Enterprise, Ultimate and Architect editions of Delphi... it is not available in Pro or Starter!
Still, you can always use ODBC on your own server tier to connect to any ODBC database (which includes MySQL, MSSQL, Oracle... even MS Access if you feel like enjoying a "blast from the past"), then use any networking socket solution you like (such as Indy which ships with Delphi [all editions] as standard) to link your Client applications to the Server tier! Look at TADOConnection, TADOQuery etc.
Hope you find this info useful!
根据实际的应用程序需求,您必须在 2 层(数据库和胖客户端)或 n 层(数据库、应用程序服务器、瘦客户端)解决方案之间进行选择。 2 层解决方案开发起来更简单,而 n 层解决方案则更复杂。
dbExpress、UniDAC、ecc。是数据库访问库。 Datasnap、Web 服务等都是 RPC(远程过程调用)框架,也可用于访问远程数据(在服务器端使用数据库访问库)。套接字只是非常低级的通信设备。
因此,您必须使用这些组件的堆栈来构建数据库访问层。例如,您可以使用dbExpress来访问DB和Datasnap作为中间层。
从安全角度来看,Datasnap 非常不安全,但 DCOM 实现由于使用的算法和密码/证书管理而非常不安全。如果您将数据库密码存储在客户端中,那么无论如何您都会遇到很大的安全问题。有一些方法(例如操作系统身份验证等)允许使用用户帐户安全性连接到数据库。使用与数据库的单个“连接”可能意味着失去一些(或很多)安全性,因为数据库访问控制将仅限于该连接用户的权限。此外,审计也可能会丢失。
当引入新层时,必须设计可扩展性并将其良好编码到该层中。数据库服务器的设计和编码是可扩展的,糟糕的中间层可能会成为瓶颈。
MySQL通常对你使用什么库来连接很挑剔,其他数据库则较少。
Depending on the actual applications needs, you have to choose between a 2-tier (database and fat client) or n-tier (database, application server, thin client) solution. A 2-tier solution is simpler to develop, and n-tier is more complex.
dbExpress, UniDAC, ecc. are db access libraries. Datasnap, web services, etc. are RPC (remote procedure call) frameworks that can be used to access remote data also (using a db access library on the server side). Sockets are just very low level communication devices.
Thereby you have to use a stack of those components to build a database access layer. For example you can use dbExpress to access the DB and Datasnap as the middle layer.
From a security point of view, Datasnap is very unsecure but the DCOM implementation because of algortithms used and password/certificate management. If you're storing database passwords in your clients you have a big security issue anyway. There are ways like operating system autentication and the like that allows for connecting to a database using the user account security. Using a single "connection" to the database may mean to lose some (or much) security, because database access controls will be limited to the permissions of that connection user. Also, auditing could be lost.
When introducing a new layer, scalability must be designed and well coded into that layer. Database servers are designed and coded to be scalable, a bad middle layer can become a bottleneck.
MySQL is usually picky about what of his lib you use to connect, other database are less.