VB.NET: 无法从客户端应用程序连接到 Oracle 数据库服务器

VB.NET: Unable to connect to an Oracle database server from client app

我在同一个本地网络 (Wi-Fi) 上有 2 台笔记本电脑(A 和 B)。

我在笔记本电脑A上安装了Oracle数据库12c r2

我在笔记本电脑 A 中创建了一个 VB.NET 应用程序 Visual Studio 2017,它可以连接到 Oracle 数据库。

该应用程序在笔记本电脑 A 上运行良好。它连接到数据库,这是我的应用程序表单,以及我使用的连接字符串(192.168.20.98 是我的笔记本电脑 A 的 IP 地址):

oracle_connection = New OracleConnection(
    "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=" & protocol.Text &
    ")(HOST=" & host.Text & ")(PORT=" & port.Text &
    ")))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=" & db_name.Text &
    ")));User Id=" & user_id.Text & ";Password=" & pswd.Text)

我还编辑了位于 C:\app\mustafa\product.2.0\dbhome_1\network\adminlistener.oratnsnames.ora 如下:

listener.ora:

# listener.ora Network Configuration File: 
C:\app\mustafa\product.2.0\dbhome_1\network\admin\listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = C:\app\mustafa\product.2.0\dbhome_1)
(PROGRAM = extproc)
(ENVS = 
"EXTPROC_DLLS=ONLY:C:\app\mustafa\product.2.0\dbhome_1\bin\oraclr12.dll")
)
)

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.20.98)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

tnsnames.ora:

# tnsnames.ora Network Configuration File: 
C:\app\mustafa\product.2.0\dbhome_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

DB1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.20.98)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = db1)
)
)

LISTENER_DB1 =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.20.98)(PORT = 1521))


ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)

我已编辑我的 Oracle 主文件夹权限以授予 authenticated users 完全访问权限。

所以当我将我的应用程序移动到笔记本电脑 B 并运行它连接到笔记本电脑 A 上的数据库时,我收到了这个错误:

System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.

我找不到任何解决方案。我的笔记本B上是否也需要安装Oracle database 12c r2?

System.Data.OracleClient 命名空间是 Oracle 的 .NET Framework 数据提供程序,但它仍然需要在目标计算机上安装 Oracle 客户端软件:

Oracle and ADO.NET | Microsoft Docs

The .NET Framework Data Provider for Oracle provides access to an Oracle database using the Oracle Call Interface (OCI) as provided by Oracle Client software.

并且:

.NET Framework Data Providers | Microsoft Docs

For Oracle data sources. The .NET Framework Data Provider for Oracle supports Oracle client software version 8.1.7 and later, and uses the System.Data.OracleClient namespace.

但是,正如文档中所述:

Note

The types in System.Data.OracleClient are deprecated. The types remain supported in the current version of.NET Framework but will be removed in a future release. Microsoft recommends that you use a third-party Oracle provider.

所以,最好使用 Oracle Data Provider for .NET (ODP.NET), instead of the deprecated System.Data.OracleClient. Here there's a 3 steps migration article 来帮助处理。

无论如何,Microsoft 或 Oracle 数据提供者仍需要在目标机器上安装 Oracle Client 软件。 Oracle 客户端软件名为 Oracle Instant Client,可以在 here.

找到

如果您已经在目标机器上安装了 Oracle Instant Client,您可以尝试其中之一(我认为问题的作者已经做过):