c# – 如何在Oracle的连接字符串中设置初始目录?

我正在尝试设置
IdentityServer3以使用Oracle数据库.我有工作的MSSQL解决方案,我也需要Oracle变体.

初始化期间,我收到以下错误.看起来提供程序达到超时(30-45秒)然后抛出异常.

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

System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create中发生错误.更具体一点

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

这是我的web.config连接字符串:

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

这是web.config的其余部分(任何与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>

如何将初始目录添加到Oracle的连接字符串中?

版本

> IdentityServer3:v 2.5
> EntityFramework:6.1.3
> Oracle ManagedDataAccess EntityFramework:12.1.4

更新1:

我试过简单地将初始目录添加到我的conn字符串中,但它似乎不起作用(Oracle XE, C++ ADO):

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

也许XE不是我的数据库的名称?我应该使用架构吗?

最佳答案 问题是defaultConnectionFactory

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

在用OracleConnectionFactory替换后,事情继续进行

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