如何连接到一个远程Oracle数据库连接到、数据库、Oracle

2023-09-04 11:08:00 作者:遍体鳞痛つ殇

我要连接到远程的Oracle数据库管理系统在我的.NET C#的Web服务

I have to connect to a remote Oracle DBMS into my .NET C# web service

是要求在客户端安装Oracle?为什么呢? 当你使用ODP.NET

感谢

推荐答案

我建议使用ODP.NET,因为它是免费的,是官方的ADO.NET兼容的供应商连接到Oracle。 1

I recommend using ODP.NET, as it's free and is the "official" ADO.NET compatible provider for connecting to Oracle.1

要饶你一用户不必单独安装Oracle客户端,下载的 Oracle即时客户端,采取下列文件从那里......

To spare your users from having to separately install the Oracle Client, download the Oracle Instant Client, take the following files from there...

oci.dll
Oracle.DataAccess.dll (the managed ODP.NET assembly itself)
orannzsbb11.dll
oraociei11.dll
OraOps11w.dll

...和你的应用程序分发。

...and distribute them with your application.

不幸的是,大多数这些DLL中的原生(32位/ 64位特定的),所以你将无法搭建任何CPU平台(但 2 )。

Unfortunately, most of these DLLs are native (and 32-bit / 64-bit specific), so you won't be able to build for "Any CPU" platform (yet2).

在.NET code是相同的你胖Oracle客户端下,会用什么(和非常类似于其他任何ADO.NET提供者那里),但你或许应该考虑使用的tnsnames.ora独立连接字符串如:

The .NET code is identical to what you would use under "fat" Oracle Client (and is very similar to any other ADO.NET provider out there), except you should probably consider using "tnsnames.ora independent" connection string such as:

Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;

1 有商业选择和老微软的供应商,现在是很precated(不使您不必安装Oracle本机DLL呢)。

1 There are commercial alternatives and the old Microsoft's provider that is now deprecated (and won't save you from having to install Oracle native DLLs anyway).

2 或者等待的完全托管Oracle提供或编辑项目文件(的MSBuild XML)有条件地包括根据不同的构建平台上的32位或64位的DLL,与此类似:的

2 Either wait for Fully Managed Oracle Provider, or edit your project file (the MSBuild XML) to conditionally include 32-bit or 64-bit DLLs depending on the build platform, similar to this:

  <Choose>
    <When Condition="'$(Platform)' == 'x64'">
      <ItemGroup>
        <Reference Include="Oracle.DataAccess, processorArchitecture=x64">
          <SpecificVersion>False</SpecificVersion>
          <HintPath>..\ThirdParty\ODP.NET\x64\Oracle.DataAccess.dll</HintPath>
        </Reference>
        <Content Include="..\ThirdParty\ODP.NET\x64\oci.dll">
          <Link>oci.dll</Link>
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
        <Content Include="..\ThirdParty\ODP.NET\x64\orannzsbb11.dll">
          <Link>orannzsbb11.dll</Link>
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
        <Content Include="..\ThirdParty\ODP.NET\x64\oraociei11.dll">
          <Link>oraociei11.dll</Link>
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
        <Content Include="..\ThirdParty\ODP.NET\x64\OraOps11w.dll">
          <Link>OraOps11w.dll</Link>
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
      </ItemGroup>
    </When>
    <When Condition="'$(Platform)' == 'x86'">
      <ItemGroup>
        <Reference Include="Oracle.DataAccess, processorArchitecture=x86">
          <SpecificVersion>False</SpecificVersion>
          <HintPath>..\ThirdParty\ODP.NET\x86\Oracle.DataAccess.dll</HintPath>
        </Reference>
        <Content Include="..\ThirdParty\ODP.NET\x86\oci.dll">
          <Link>oci.dll</Link>
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
        <Content Include="..\ThirdParty\ODP.NET\x86\orannzsbb11.dll">
          <Link>orannzsbb11.dll</Link>
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
        <Content Include="..\ThirdParty\ODP.NET\x86\oraociei11.dll">
          <Link>oraociei11.dll</Link>
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
        <Content Include="..\ThirdParty\ODP.NET\x86\OraOps11w.dll">
          <Link>OraOps11w.dll</Link>
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
      </ItemGroup>
    </When>
  </Choose>