Estoy tratando de hacer que el predeterminado ASP.NET aplicación MVC uso remoto de base de datos Oracle. He instalado el cliente de oracle y puede tener acceso a la base de datos remota desde el Explorador de servidores.
He intentado cambiar la cadena de conexión de

 <connectionStrings>
    <add name="ApplicationServices"
         connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

a

<connectionStrings>
    <add name="ApplicationServices"
         connectionString="Data Source=orcl;Persist Security Info=True;User ID=username;Password=mypassword;Unicode=True"
         providerName="Oracle.DataAccess.Client" />
  </connectionStrings>

He usado la cadena de conexión desde el Explorador de servidores > Conexión de Datos > orcl.ejemplo

A la hora de crear un usuario nuevo, recibo el siguiente error en AccountModels.cs

An error occurred while attempting to initialize a System.Data.SqlClient.SqlConnection object. The value that was provided for the connection string may be wrong, or it may contain an invalid syntax.
Parameter name: connectionString

Alguna idea de lo que me estoy perdiendo aquí?

EDITAR:
Se ve como el siguiente fragmento de código en AccountModels.cs utiliza System.Data.SqlClient.SqlConnection. ¿Cómo puedo utilizar el ODP versión.

 public class AccountMembershipService : IMembershipService
    {
        private readonly MembershipProvider _provider;
        ...
    }
InformationsquelleAutor devnull | 2011-12-05

3 Comentarios

  1. 4

    Tienes que utilizar ODP.NET API en lugar de SqlClient proveedor. El System.Data.SqlClient clases son para Microsoft SQL server base de datos única.

    EDICIÓN:

    Oracle artículo : Oracle Proveedores para ASP.NET Instalación

  2. 0

    He usado DevArt Oracle Conector he modificado mi web.config como este

    <?xml version="1.0" encoding="utf-8"?>
    <!--
    For more information on how to configure your ASP.NET application, please visit
    http://go.microsoft.com/fwlink/?LinkId=301880
    -->
    <configuration>
    <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    </configSections>
    <connectionStrings >
    <!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-oapp-20140623054602.mdf;Initial Catalog=aspnet-oapp-20140623054602;Integrated Security=True"
    providerName="System.Data.SqlClient" />-->
    <add name="DefaultConnection"  connectionString="User Id=demouser;Password=demo123;Server=oracle;Direct=True;Sid=orcl;" providerName="Devart.Data.Oracle" />
    </connectionStrings>
    <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    </appSettings>
    <system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <roleManager enabled="true" defaultProvider="OracleExtendedRoleProvider">
    <providers>
    <clear />
    <remove name="OracleExtendedRoleProvider" />
    <!--<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />-->
    <add name="OracleExtendedRoleProvider" type="Devart.Data.Oracle.Web.Providers.OracleExtendedRoleProvider, Devart.Data.Oracle.Web,              Version=8.4.181.4, Culture=neutral, PublicKeyToken=09af7300eec23701" connectionStringName="DefaultConnection" />
    </providers>
    </roleManager>
    <profile defaultProvider="OracleExtendedProfileProvider">
    <!-- <properties>
    <add name="friendlyName"/>
    </properties>-->
    <providers>
    <remove name="OracleExtendedProfileProvider" />
    <add name="OracleExtendedProfileProvider" type="Devart.Data.Oracle.Web.Providers.OracleProfileProvider, Devart.Data.Oracle.Web,               Version=8.4.181.4, Culture=neutral, PublicKeyToken=09af7300eec23701" connectionStringName="DefaultConnection" />
    </providers>
    </profile>
    <membership defaultProvider="OracleExtendedMembershipProvider">
    <providers>
    <remove name="OracleExtendedMembershipProvider" />
    <add name="OracleExtendedMembershipProvider" type="Devart.Data.Oracle.Web.Providers.OracleMembershipProvider, Devart.Data.Oracle.Web,               Version=8.4.181.4 Culture=neutral, PublicKeyToken=09af7300eec23701" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" passwordAttemptWindow="10" />
    </providers>
    </membership>
    <sessionState mode="InProc" customProvider="OracleSessionProvider">
    <providers>
    <add name="OracleSessionProvider" type="Devart.Data.Oracle.Web.Providers.OracleSessionStateStore,Devart.Data.Oracle.Web,               Version=8.4.181.4, Culture=neutral, PublicKeyToken=09af7300eec23701" connectionStringName="OracleServices" />
    </providers>
    </sessionState>
    <siteMap defaultProvider="OracleSiteMapProvider">
    <providers>
    <add name="OracleSiteMapProvider" type="Devart.Data.Oracle.Web.Providers.OracleSiteMapProvider, Devart.Data.Oracle.Web,               Version=8.4.181.4, Culture=neutral, PublicKeyToken=09AF7300EEC23701" connectionStringName="DefaultConnection" securityTrimmingEnabled="true" />
    </providers>
    </siteMap>
    </system.web>
    <system.webServer>
    <modules>
    <remove name="FormsAuthenticationModule" />
    </modules>
    </system.webServer>
    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31BF3856AD364E35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="System.Web.Razor" publicKeyToken="31BF3856AD364E35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
    </dependentAssembly>
    </assemblyBinding>
    </runtime>
    <entityFramework codeConfigurationType="oapp.Models.MyDbConfiguration, oapp">
    <!-- <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
    <parameters>
    <parameter value="v11.0"/>
    </parameters>
    </defaultConnectionFactory>-->
    <providers>
    <provider invariantName="Devart.Data.Oracle" type="Devart.Data.Oracle.Entity.OracleEntityProviderServices, Devart.Data.Oracle.Entity, Version=8.4.181.6, Culture=neutral, PublicKeyToken=09af7300eec23701" />
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
    <parameters>
    <parameter value="v11.0" />
    </parameters>
    </defaultConnectionFactory>
    </entityFramework>
    </configuration>

    Esto funcionó para mí.
    Después de esto también tengo problema en ProviderService Proyecto fue incapaz de encontrarla. así que he modificado este código en IdentityModels.cs

    using System.Security.Claims;
    using System.Threading.Tasks;
    using Microsoft.AspNet.Identity;
    using Microsoft.AspNet.Identity.EntityFramework;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    namespace oapp.Models
    {
    // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
    public class ApplicationUser : IdentityUser
    {
    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
    {
    // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
    var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
    // Add custom user claims here
    return userIdentity;
    }
    }
    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
    public ApplicationDbContext()
    : base("DefaultConnection", throwIfV1Schema: false)
    {
    }
    public static ApplicationDbContext Create()
    {
    return new ApplicationDbContext();
    }
    static ApplicationDbContext()
    {
    var config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
    config.CodeFirstOptions.TruncateLongDefaultNames = true;
    Database.SetInitializer(new MigrateDatabaseToLatestVersion<ApplicationDbContext, Configuration>());
    }
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
    base.OnModelCreating(modelBuilder);
    modelBuilder
    .Properties()
    .Where(p => p.PropertyType == typeof(string) &&
    !p.Name.Contains("Id") &&
    !p.Name.Contains("Provider"))
    .Configure(p => p.HasMaxLength(256));
    }
    }
    internal class Configuration : DbMigrationsConfiguration<ApplicationDbContext>
    {
    public Configuration()
    {
    AutomaticMigrationsEnabled = true;
    SetSqlGenerator("Devart.Data.Oracle", new Devart.Data.Oracle.Entity.Migrations.OracleEntityMigrationSqlGenerator());
    }
    }
    public class MyDbConfiguration :  DbConfiguration
    {
    public MyDbConfiguration()
    {
    // this.AddDbProviderServices("Devart.Data.Oracle", new Devart.Data.Oracle.Entity.OracleEntityProviderServices());
    this.SetProviderServices("Devart.Data.Oracle", new Devart.Data.Oracle.Entity.OracleEntityProviderServices());
    }
    }
    }

    esperanza de que esto funcionará para usted también.

  3. 0

    Tienes que usar «ODP.NET» API en lugar de «SqlClient» el proveedor. usted puede encontrar más detalles de ESTE blog. Después de la instalación de acuerdo con el proceso, no es necesario cambiar las cadenas de conexión.

Dejar respuesta

Please enter your comment!
Please enter your name here