pizycki pizycki - 9 days ago 5
C# Question

How to set Initial Catalog in connection string for Oracle?

I'm trying to setup IdentityServer3 to work with Oracle database. I've got working MSSQL solution and I need Oracle variation too.

During initialization I get following error. It looks like provider reaches timeout (30-45 s) and then throws the exception.

The supplied SqlConnection does not specify an initial catalog or AttachDBFileName.


Error occurs in
System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create
. To be more specific in

IdentityServer3.EntityFramework.DbModelBuilderExtensions
.RegisterScopeChildTablesForDelete[TScope](DbContext ctx) in
IdentityServer3.EntityFramework\Source\Core.EntityFramework\Extensions
\DbModelBuilderExtensions.cs


Here is my
web.config
connection string:

<add name="ApplicationDbContext"
providerName="Oracle.ManagedDataAccess.Client"
connectionString="User Id=xxxxxxx;
Password=xxxxxxx;
Data Source=OracleDataSource" />


and here is the rest of
web.config
(any how related to Oracle)

<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>

<system.data>
<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>
</system.data>

<oracle.manageddataaccess.client>
<version number="*">
<dataSources>
<dataSource alias="OracleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE))) " />
</dataSources>
</version>
</oracle.manageddataaccess.client>


How can I add
Initial Catalog
to my connection string for Oracle?

Versions


  • IdentityServer3: v 2.5

  • EntityFramework: 6.1.3

  • Oracle ManagedDataAccess EntityFramework: 12.1.4



Update 1:

I've tried simply adding
Initial Catalog
to my conn string, but it doesn't seem to work (Oracle XE, C++ ADO):

<add name="ApplicationDbContext"
providerName="Oracle.ManagedDataAccess.Client"
connectionString="User Id=xxxxxxx;
Password=xxxxxxx;
Data Source=OracleDataSource;
Initial catalog=XE" />


Maybe
XE
is not the name of my database? Should I use
schema
instead?

Answer

The problem was defaultConnectionFactory

<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />

After replacing with OracleConnectionFactory things moved on

<defaultConnectionFactory type="Oracle.ManagedDataAccess.EntityFramework.OracleConnectionFactory, Oracle.ManagedDataAccess.EntityFramework" />