ASP.NET MVC 5,Oracle.ManagedDataAccess和SQL DB

时间:2015-05-15 15:17:34

标签: sql-server oracle entity-framework asp.net-mvc-5

我想使用SQL Server数据库来识别身份,但是在Oracle数据库中使用数据(crud)。

我可以使用Oracle.ManagedDataAccess包连接到Oracle。任何人都可以指导我如何设置DbContext /无论什么?

我已在网络配置中设置了这个:

<connectionStrings>  
    <add name="SQLServerConnect" 
         connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MVC-Oracle-HR-Test-20150514042443.mdf;Initial Catalog=aspnet-MVC-Oracle-HR-Test-20150514042443;Integrated Security=True" 
         providerName="System.Data.SqlClient" />
    <add name="Oracle" 
         connectionString="Data Source=v-oratesting/syscntrl;Persist Security Info=True;User ID=MYUSERID;Password=MYPASSWORD;" 
         providerName="Oracle.ManagedDataAccess.Client"/>
</connectionStrings>
<appSettings>
    ...
    <add key="DefaultConnection" value="Oracle" />
    <add key="SqlServerConnection" value="SQLServerConnect" />
</appSettings>

public ApplicationDbContext()
        : base("SqlServerConnection", throwIfV1Schema: false)
{
}

在我的identityModels.cs中。到目前为止,这将在SQL Server数据库中创建一个用户帐户,如何设置将Oracle连接用于其他数据模型和控制器?

1 个答案:

答案 0 :(得分:0)

嗯,这可行:连接字符串

-c

identitymodels.cs:

   <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\MVC-Oracle-Test-20150519031928.mdf;Initial Catalog=MVC-Oracle-Test-20150519031928;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="OracleDbContextConnection" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=xxx;Password=xxxx;Data Source=v-oratest/xxxxxx" />