如何设置 OLEDB 以连接到远程数据库?
我在本地运行 Oracle 11g 数据库。我有一个小程序通过 VC++ 中的 OLEDB 在代码中连接到它(它只运行一些数据库测试,我确保在进入实际操作之前我已经掌握了所有基础知识。)代码中的连接信息仅包括提供者、实例名称、用户名和密码。所有这方面都运作良好。
//For example, both these ways of connecting work:
result = dataSource.Open(DATABASE_PROVIDER, DATABASE_NAME,
DATABASE_USER_NAME, DATABASE_USER_PASSWORD);
result = dataSource.OpenFromInitializationString(L"Provider=OraOLEDB.OracleDataSource=orcl;User ID=SYSTEM;Password=admin;");
我现在想将此程序发送到网络中的其他计算机并从那里运行它,连接到本地计算机上的数据库。
我将如何以代码能够理解的方式将其他计算机连接到我的数据库?
我一直在尝试通过 IP 而不是“localhost”进行本地连接,认为我可以简单地使用相同的代码和客户端。在这方面,我尝试了一些方法但没有成功:
-我尝试修改连接字符串以将“数据源”更改为我的IP,但无法连接。
-我尝试从我见过的其他连接字符串示例中添加一些参数,但它们不适用于 Oracle,因此被忽略。
-我还尝试修改tnsnames.ora和listener.ora以将本地主机更改为IP地址,但我知道这不起作用,因为如果我输入垃圾,它仍然会连接。
有知道的朋友帮忙解答一下吗?
I am locally running an Oracle 11g database. I have a small program connecting to it in code via OLEDB in VC++ (It only runs some database tests, I'm making sure I have all the basics down before I go into the real thing.) The connection information in code only includes the provider, instance name, user name, and password. All this aspect works fine.
//For example, both these ways of connecting work:
result = dataSource.Open(DATABASE_PROVIDER, DATABASE_NAME,
DATABASE_USER_NAME, DATABASE_USER_PASSWORD);
result = dataSource.OpenFromInitializationString(L"Provider=OraOLEDB.OracleDataSource=orcl;User ID=SYSTEM;Password=admin;");
I now want to send this program to other computers in my network and run it from there, connecting to my database on my local machine.
How would I go about connecting the other computers to my database in a way that the code will understand?
I have been trying to connect locally via IP instead of "localhost", figuring I could then simply use the same code and client. In that regard, I have tried a few things without success:
-I have tried modifying the connection string to change "Data Source" to my IP, but it could not connect.
-I have tried adding some parameters from other connection string examples I had seen, but they were not for Oracle and were ignored.
-I have also tried modifying tnsnames.ora and listener.ora to change local host to an IP address, but I know that didn't work, as it would still connect if I entered rubbish.
Anyone has the knowledge to help out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 Oracle 数据库,您应该在其各自的计算机上设置一个新的 tnsnames 条目,该条目指向您的本地数据库。然后使用新的 tns 名称作为数据源。您还需要首先确保他们可以访问您的本地数据库实例。 (顺便说一下,Oracle Express 中默认情况下未启用此功能。)
我通常使用 msdaora 作为数据提供程序(而不是 OraOLEDB)取得了更大的成功。
For an Oracle db, you should set up a new tnsnames entry on their individual machines that points to your local db. Then use that new tns name as the datasource. You'll also need to make sure that your local db instance is accessible to them in the first place. (This is not enabled by default in Oracle Express, by the way.)
I've also generally had more success using msdaora as the data provider instead of OraOLEDB.