简体   繁体   中英

c# Connect to Oracle database

I have ac# application with Entity Framework with a connection to an Oracle Database. This connections works fine on my development pc and also on an older shared windows 2008 server.

Now I deployed it on a new windows 2012 test server and the server throws an error that he can't connect to the database.

The server is available when I telnet its IP and port 1521, so it should be connectable.

This is the relevant web.config code:

<connectionStrings>
    <add name="Context" connectionString="DATA SOURCE=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=XXX)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XXX)));USER ID=XXX;PASSWORD=XXX;PERSIST SECURITY INFO=False" providerName="Oracle.ManagedDataAccess.Client" />
</connectionStrings>

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
        <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </providers>
</entityFramework>  

<DbProviderFactories>
    <remove invariant="Oracle.ManagedDataAccess.Client" />
    <add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>

This is the error I got:

System.Data.Entity.Core.ProviderIncompatibleException

"An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure."

"Connection request timed out"


Question: How can I solve this database connection? Do I miss something?

Having struggled some years ago with connection to Oracle servers I used the TOAD freeware version to debug the connection strings. It was a life saver. Also, I needed the assistance of the Oracle DBAs.

It looks like your application might not be able to find the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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