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

时间:2016-11-23 14:14:08

标签: c# oracle entity-framework connection-string identityserver3

我尝试设置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>

如何将Initial Catalog添加到Oracle的连接字符串中?

版本

  • IdentityServer3:v 2.5

  • EntityFramework:6.1.3

  • Oracle ManagedDataAccess EntityFramework:12.1.4

更新1:

我尝试过简单地将Initial Catalog添加到我的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不是我的数据库的名称?我应该使用schema吗?

1 个答案:

答案 0 :(得分:2)

问题是defaultConnectionFactory

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

替换为OracleConnectionFactory移动的内容

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