Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Use NopCommerce with Database Oracle

jPcSMay 20 2015 — edited May 20 2015

Hello I ask for help and I want to implement the Nop-commerce platform, but with connection to my oracle database searching the internet basing on a post where it was set up to MySql  i create two classes:

the solution is in asp.mvc 

mainly concerns me is that it fails to identify the provider of oracle so I appreciate all the help

------------------------- OracleConnectionFactory :-------------class

OracleConnectionFactory :



using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Data.Entity.Infrastructure;

using System.Data.Common;

using Oracle.ManagedDataAccess.Client;

namespace Nop.Data

{

    public sealed class OracleConnectionFactory : IDbConnectionFactory

    {

        private readonly string _baseConnectionString;

        private Func<string, DbProviderFactory> _providerFactoryCreator;

        public OracleConnectionFactory()

        {

        }

        public OracleConnectionFactory(string baseConnectionString)

        {

            this._baseConnectionString = baseConnectionString;

        }

        public DbConnection CreateConnection(string nameOrConnectionString)

        {

            string connectionString = nameOrConnectionString;

            bool treatAsConnectionString = nameOrConnectionString.IndexOf('=') >= 0;

            if (!treatAsConnectionString)

            {

                OracleConnectionStringBuilder builder = new OracleConnectionStringBuilder(this.BaseConnectionString);

                connectionString = builder.ConnectionString;

            }

            DbConnection connection = null;

            try

            {

                connection = this.ProviderFactory("ODP.NET, Managed Driver").CreateConnection();

                //var factory = DbProviderFactories.GetFactory("ODP.NET, Managed Driver");

                //var conn = factory.CreateConnection();

                //onnection = conn;

                connection.ConnectionString = connectionString;

            }

            catch (Exception)

            {

                connection = new OracleConnection(connectionString);

            }

            return connection;

        }

        public string BaseConnectionString

        {

            get

            {

                return this._baseConnectionString;

            }

        }

        internal Func<string, DbProviderFactory> ProviderFactory

        {

            get

            {

                Func<string, DbProviderFactory> func1 = this._providerFactoryCreator;

                return delegate(string name)

                {

                    return DbProviderFactories.GetFactory(name);

                };

            }

            set

            {

                this._providerFactoryCreator = value;

            }

        }

    }

}

And------------------------- OracleProvider:-------------class

using System;

using System.Collections.Generic;

using System.Data.Common;

using System.Data.Entity;

using System.Data.Entity.Infrastructure;

using System.Data.SqlClient;

using System.IO;

using System.Text;

using System.Web.Hosting;

using Nop.Data.Initializers;

using Nop.Core.Data;

using Oracle.ManagedDataAccess.Client;

namespace Nop.Data

{

    public class OracleDataProvider : IDataProvider

    {

        #region utilities

        protected virtual string[] ParseCommands(string filePath, bool throwExceptionIfNonExists)

        {

            if (!File.Exists(filePath))

            {

                if (throwExceptionIfNonExists)

                    throw new ArgumentException(string.Format("Specified file doesn't exist - {0}", filePath));

                return new string[0];

            }

            var statements = new List<string>();

            using (var stream = File.OpenRead(filePath))

            using (var reader = new StreamReader(stream))

            {

                string statement;

                while ((statement = ReadNextStatementFromStream(reader)) != null)

                {

                    statements.Add(statement);

                }

            }

            return statements.ToArray();

        }

        protected virtual string ReadNextStatementFromStream(StreamReader reader)

        {

            var sb = new StringBuilder();

            string lineOfText;

            while (true)

            {

                lineOfText = reader.ReadLine();

                if (lineOfText == null)

                {

                    if (sb.Length > 0)

                        return sb.ToString();

                    else

                        return null;

                }

                //MySql doesn't support GO, so just use a commented out GO as the separator

                if (lineOfText.TrimEnd().ToUpper() == "-- GO")

                    break;

                sb.Append(lineOfText + Environment.NewLine);

            }

            return sb.ToString();

        }

        #endregion

        #region Methods

        /// <summary>

        /// Initialize connection factory

        /// </summary>

        public virtual void InitConnectionFactory()

        {

            //var connectionFactory = new SqlConnectionFactory();

            var connectionFactory = new OracleConnectionFactory("OracleDbContext");

            //TODO fix compilation warning (below)

            #pragma warning disable 0618

            Database.DefaultConnectionFactory = connectionFactory;

        }

        /// <summary>

        /// Initialize database

        /// </summary>

        public virtual void InitDatabase()

        {

            InitConnectionFactory();

            SetDatabaseInitializer();

        }

         /// <summary>

        /// Set database initializer

        /// </summary>

        public virtual void SetDatabaseInitializer()

        {

            //pass some table names to ensure that we have nopCommerce 2.X installed

            var tablesToValidate = new[] { "Customer", "Discount", "Order", "Product", "ShoppingCartItem" };

            //custom commands (stored proedures, indexes)

            var customCommands = new List<string>();

            //use webHelper.MapPath instead of HostingEnvironment.MapPath which is not available in unit tests

            //customCommands.AddRange(ParseCommands(HostingEnvironment.MapPath("~/App_Data/Install/SqlServer.Indexes.sql"), false));

            //use webHelper.MapPath instead of HostingEnvironment.MapPath which is not available in unit tests

            //customCommands.AddRange(ParseCommands(HostingEnvironment.MapPath("~/App_Data/Install/SqlServer.StoredProcedures.sql"), false));

            var initializer = new CreateTablesIfNotExist<NopObjectContext>(tablesToValidate, customCommands.ToArray());

            Database.SetInitializer(initializer);

        }

        /// <summary>

        /// A value indicating whether this data provider supports stored procedures

        /// </summary>

        public virtual bool StoredProceduredSupported

        {

            get { return true; }

        }

        /// <summary>

        /// Gets a support database parameter object (used by stored procedures)

        /// </summary>

        /// <returns>Parameter</returns>

        public virtual DbParameter GetParameter()

        {

            //return new SqlParameter();

            return new OracleParameter();

        }

        #endregion

    }

}

--------------------------- web.config /////////////////////////////////////////

<?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=152368

  -->

<configuration>

  <configSections>

    <section name="NopConfig" type="Nop.Core.Configuration.NopConfig, Nop.Core" requirePermission="false" />

    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->

    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

    <!-- image resizer -->

    <section name="resizer" type="ImageResizer.ResizerSection,ImageResizer" requirePermission="false" />

    <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />

    <section name="oracle.dataaccess.client" type="System.Data.Common.DbProviderConfigurationHandler, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

  </configSections>

  <NopConfig>

    <DynamicDiscovery Enabled="true" />

    <Engine Type="" />

    <Themes basePath="~/Themes/" />

    <!-- you can get the latest version of user agent strings at http://user-agent-string.info/ -->

    <UserAgentStrings databasePath="~/App_Data/uas_20140809-02.ini" />

  </NopConfig>

  <!-- image resizer -->

  <resizer>

    <plugins>

      <add name="PrettyGifs" />

    </plugins>

  </resizer>

  <appSettings>

    <add key="webpages:Version" value="3.0.0.0" />

    <add key="webpages:Enabled" value="false" />

    <add key="PreserveLoginUrl" value="true" />

    <add key="ClientValidationEnabled" value="true" />

    <add key="UnobtrusiveJavaScriptEnabled" value="true" />

    <add key="ClearPluginsShadowDirectoryOnStartup" value="False" />

    <!-- By default this setting should always be set to "False" (only for advanced users)-->

    <add key="UseFastInstallationService" value="False" />

    <!-- A value indicating whether a store owner can install sample data during installation-->

    <add key="DisableSampleDataDuringInstallation" value="False" />

    <!-- A list of plugins ignored during nopCommerce installation-->

    <add key="PluginsIgnoredDuringInstallation" value="" />

    <!-- Set the setting below to "false" if you did not upgrade from one of the previous versions. It can slightly improve performance -->

    <add key="SupportPreviousNopcommerceVersions" value="True" />

  </appSettings>

  <system.web>

    <customErrors defaultRedirect="errorpage.htm" mode="RemoteOnly">

      <!-- We handle all 404 errors in "PageNotFound" method of "CommonController". But let's have it here anyway. -->

      <error statusCode="404" redirect="filenotfound.htm" />

    </customErrors>

    <trace enabled="false" localOnly="true" />

    <compilation debug="true" targetFramework="4.5.1" />

    <authentication mode="Forms">

      <forms name="NOPCOMMERCE.AUTH" loginUrl="~/login" protection="All" timeout="43200" path="/" requireSSL="false" slidingExpiration="true" />

    </authentication>

    <pages>

      <namespaces>

        <add namespace="System.Web.Helpers" />

        <add namespace="System.Web.Mvc" />

        <add namespace="System.Web.Mvc.Ajax" />

        <add namespace="System.Web.Mvc.Html" />

        <add namespace="System.Web.Optimization" />

        <add namespace="System.Web.Routing" />

        <add namespace="System.Web.WebPages" />

      </namespaces>

    </pages>

    <httpRuntime targetFramework="4.5.1" />

  </system.web>

  <system.webServer>

    <modules runAllManagedModulesForAllRequests="false">

      <!-- <remove name="UrlRoutingModule-4.0" />

      <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />-->

    </modules>

    <staticContent>

      <!--Cache static content for 24 hours-->

      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="24.00:00:00" />

      <!--Allow json file loading (used by Roxy Fileman)-->

      <remove fileExtension=".json" />

      <mimeMap fileExtension=".json" mimeType="application/json" />

    </staticContent>

    <urlCompression doStaticCompression="true" doDynamicCompression="true" />

    <validation validateIntegratedModeConfiguration="false" />

    <handlers>

      <remove name="OPTIONSVerbHandler" />

      <remove name="TRACEVerbHandler" />

      <add name="SitemapXml" path="sitemap.xml" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />

      <add name="RobotsTxt" path="robots.txt" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />

      <add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />

      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />

      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

    </handlers>

  </system.webServer>

  <system.serviceModel>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

  </system.serviceModel>

  <runtime>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

      <probing privatePath="Plugins/bin/" />

      <dependentAssembly>

        <assemblyIdentity name="FluentValidation" publicKeyToken="a82054b837897c66" culture="neutral" />

        <bindingRedirect oldVersion="0.0.0.0-3.4.0.0" newVersion="3.4.0.0" />

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />

        <bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />

        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />

        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />

        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />

        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />

        <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />

        <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentity name="System.Web.Http.WebHost" publicKeyToken="31bf3856ad364e35" culture="neutral" />

        <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.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.WebPages" 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="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />

        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />

      </dependentAssembly>

      <dependentAssembly>

        <publisherPolicy apply="no" />

        <assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />

      </dependentAssembly>

    </assemblyBinding>

  </runtime>

  <system.data>

    <DbProviderFactories>

      <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />

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

  <entityFramework>

    <providers>

      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />

      <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />

      <provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />

      <!--<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.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />-->

      <!--<add name="ODP.NET, Unmanaged Driver" invariant="Oracle.DataAccess.Client" description="Oracle Data Provider for .NET, Unmanaged Driver" type="Oracle.DataAccess.Client.OracleClientFactory, Oracle.DataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />-->

    </providers>

  </entityFramework>

  <oracle.manageddataaccess.client>

    <version number="*">

      <dataSources>

        <dataSource alias="orcl" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) " />

      </dataSources>

    </version>

  </oracle.manageddataaccess.client>

  <connectionStrings>

    <add name="OracleDbContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=STARTFLEET;Password=2013$sfleet1;Data Source=orcl" />

  </connectionStrings>

</configuration>

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 17 2015
Added on May 20 2015
0 comments
2,326 views