简体   繁体   English

C++ 数据库 API - DTL

[英]C++ Database API's - DTL

I'm looking for a C++ API that is able to connect to different types of databases all in one;我正在寻找能够同时连接到不同类型的数据库的 C++ API; mainly MySQL, oracle and SQL Server and I believe I have found one with "DTL" ( http://dtemplatelib.sourceforge.net/ ) mainly MySQL, oracle and SQL Server and I believe I have found one with "DTL" ( http://dtemplatelib.sourceforge.net/ )

However, I'm struggling to connect my database on localhost.但是,我正在努力在 localhost 上连接我的数据库。 Has anyone used this before and could shed some more light on it other than what their site does with有没有人用过这个,除了他们的网站做什么之外,还可以对它有更多的了解

DBConnection::GetDefaultConnection().Connect("UID=example;PWD=example;DSN=example;");

though I guess what to put in uid and pwd, I'm not sure what it's expecting in 'dsn', are there any REAL examples or have you guys used it before and could help.虽然我猜想在 uid 和 pwd 中放什么,但我不确定它在“dsn”中的期望是什么,是否有任何真实的例子或者你们以前使用过它并且可以提供帮助。

This is an ODBC library, so DSN is the ODBC data source name.这是一个 ODBC 库,因此 DSN 是 ODBC 数据源名称。 On Windows, these can be configured under Administrative Tools->Data Sources.在 Windows 上,可以在管理工具->数据源下配置这些。

As @Dark Falcon said, the "DSN" refers to an "ODBC data source".正如@Dark Falcon 所说,“DSN”指的是“ODBC 数据源”。 What you get is an extra level of indirection like this:你得到的是一个额外的间接级别,如下所示:

在此处输入图像描述

On Windows, you normally create the ODBC data source with the "Data Sources (ODBC)" control panel, which is normally in the "Administrative Tools".在 Windows 上,您通常使用“数据源 (ODBC)”控制面板创建 ODBC 数据源,该控制面板通常位于“管理工具”中。

In any case, this separates the configuration/deployment "stuff" from the code.无论如何,这将配置/部署“东西”与代码分开。 For example, if you want to use your code with a test database during development, then with the "live" database when you deploy it, you can do that without making any changes to your code, and even without changing the connection string.例如,如果您想在开发期间将代码与测试数据库一起使用,然后在部署时使用“实时”数据库,您可以在不更改代码甚至不更改连接字符串的情况下执行此操作。 Instead, you change the data source to refer to production server instead of the test server.相反,您将数据源更改为引用生产服务器而不是测试服务器。

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

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