Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Need help advice

Need help advice

Scheduled Pinned Locked Moved C#
csharpasp-netdatabasesysadminxml
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hardsoft
    wrote on last edited by
    #1

    I have an app in csharp dot net version 4.7.1 and moving to dotnet version 6. The snippet of code from 4.7.1 is

    Quote:

    using System.Web; // requires a reference to System.Web.dll using System.Web.Configuration; // requires a reference to System.Configuration.dll /// /// Imports an xml store by it's relative path in ASP.NET and returns the requested connection. /// Does not open the connection. /// /// Context of HTTP request to resolve relative path with. (e.g. HttpContext.Current) /// Full or relative server path. (e.g. ~/App_Data/databases.xml) /// Returns a new instance of the provider's class that represents a connection to the database. public static DbConnection Open(HttpContextBase httpContext, string configurationFileName, string connectionName) { DbConnection connection = Connection(httpContext, configurationFileName, connectionName); connection.Open(); return connection; } /// /// Imports an xml store by it's relative path in ASP.NET and returns the requested connection. /// Does not open the connection. /// /// Context of HTTP request to resolve relative path with. (e.g. HttpContext.Current) /// Full or relative server path. (e.g. ~/App_Data/databases.xml) /// Returns a new instance of the provider's class that represents a connection to the database. /// Returns a new instance of the provider's class that represents a connection to the database. public static DbConnection Connection(HttpContextBase httpContext, string configurationFileName, string connectionName) { Sources.ImportXmlStore(httpContext.Server.MapPath(configurationFileName)); return Connection(connectionName); }

    I cannot use using System.Web; using System.Web.Configuration; as these don't exist in 6.0 so would appreciate help on how to convert the following to keep the same functionality.

    Quote:

    DbConnection connection = Connection(httpContext, configurat

    L 1 Reply Last reply
    0
    • H hardsoft

      I have an app in csharp dot net version 4.7.1 and moving to dotnet version 6. The snippet of code from 4.7.1 is

      Quote:

      using System.Web; // requires a reference to System.Web.dll using System.Web.Configuration; // requires a reference to System.Configuration.dll /// /// Imports an xml store by it's relative path in ASP.NET and returns the requested connection. /// Does not open the connection. /// /// Context of HTTP request to resolve relative path with. (e.g. HttpContext.Current) /// Full or relative server path. (e.g. ~/App_Data/databases.xml) /// Returns a new instance of the provider's class that represents a connection to the database. public static DbConnection Open(HttpContextBase httpContext, string configurationFileName, string connectionName) { DbConnection connection = Connection(httpContext, configurationFileName, connectionName); connection.Open(); return connection; } /// /// Imports an xml store by it's relative path in ASP.NET and returns the requested connection. /// Does not open the connection. /// /// Context of HTTP request to resolve relative path with. (e.g. HttpContext.Current) /// Full or relative server path. (e.g. ~/App_Data/databases.xml) /// Returns a new instance of the provider's class that represents a connection to the database. /// Returns a new instance of the provider's class that represents a connection to the database. public static DbConnection Connection(HttpContextBase httpContext, string configurationFileName, string connectionName) { Sources.ImportXmlStore(httpContext.Server.MapPath(configurationFileName)); return Connection(connectionName); }

      I cannot use using System.Web; using System.Web.Configuration; as these don't exist in 6.0 so would appreciate help on how to convert the following to keep the same functionality.

      Quote:

      DbConnection connection = Connection(httpContext, configurat

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      DbConnection is in the System.Data.Common namespace; i.e.

      using System.Data.Common;

      [DbConnection Class (System.Data.Common) | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/api/system.data.common.dbconnection?view=net-6.0)

      "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

      H 1 Reply Last reply
      0
      • L Lost User

        DbConnection is in the System.Data.Common namespace; i.e.

        using System.Data.Common;

        [DbConnection Class (System.Data.Common) | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/api/system.data.common.dbconnection?view=net-6.0)

        "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

        H Offline
        H Offline
        hardsoft
        wrote on last edited by
        #3

        Hi Gerry Thank you for your reply but that is not the issue. I have that issue is the following is not in 6.0 I have the following at the beginning of my code.

        Quote:

        using System; using System.Collections.Generic; using System.Data.Common; using System.Linq; using System.Xml.Linq; using System.Security.Cryptography; using System.Web; // requires a reference to System.Web.dll using System.Web.Configuration; // requires a reference to System.Configuration.dll

        I cannot find a reference to items in bold so looking for how to reproduce the same functionality System.Web.Configuration was required for HttpContextBase and WebConfigurationManager

        Quote:

        using System.Web.Configuration; // requires a reference to System.Configuration.dll HttpContextBase httpContext ConnectionString = WebConfigurationManager.ConnectionStrings[name].ConnectionString

        L H 2 Replies Last reply
        0
        • H hardsoft

          Hi Gerry Thank you for your reply but that is not the issue. I have that issue is the following is not in 6.0 I have the following at the beginning of my code.

          Quote:

          using System; using System.Collections.Generic; using System.Data.Common; using System.Linq; using System.Xml.Linq; using System.Security.Cryptography; using System.Web; // requires a reference to System.Web.dll using System.Web.Configuration; // requires a reference to System.Configuration.dll

          I cannot find a reference to items in bold so looking for how to reproduce the same functionality System.Web.Configuration was required for HttpContextBase and WebConfigurationManager

          Quote:

          using System.Web.Configuration; // requires a reference to System.Configuration.dll HttpContextBase httpContext ConnectionString = WebConfigurationManager.ConnectionStrings[name].ConnectionString

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          [Access HttpContext in ASP.NET Core | Microsoft Docs](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-context?view=aspnetcore-6.0) [Connection Strings - EF Core | Microsoft Docs](https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-strings) [c# - Config connection string in .net core 6 - Stack Overflow](https://stackoverflow.com/questions/68980778/config-connection-string-in-net-core-6) [Migrate configuration to ASP.NET Core | Microsoft Docs](https://docs.microsoft.com/en-us/aspnet/core/migration/configuration?view=aspnetcore-6.0)

          "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

          1 Reply Last reply
          0
          • H hardsoft

            Hi Gerry Thank you for your reply but that is not the issue. I have that issue is the following is not in 6.0 I have the following at the beginning of my code.

            Quote:

            using System; using System.Collections.Generic; using System.Data.Common; using System.Linq; using System.Xml.Linq; using System.Security.Cryptography; using System.Web; // requires a reference to System.Web.dll using System.Web.Configuration; // requires a reference to System.Configuration.dll

            I cannot find a reference to items in bold so looking for how to reproduce the same functionality System.Web.Configuration was required for HttpContextBase and WebConfigurationManager

            Quote:

            using System.Web.Configuration; // requires a reference to System.Configuration.dll HttpContextBase httpContext ConnectionString = WebConfigurationManager.ConnectionStrings[name].ConnectionString

            H Offline
            H Offline
            hardsoft
            wrote on last edited by
            #5

            Ok Found part of my solution here c# - Is ConfigurationManager.AppSettings available in .NET Core 2.0? - Stack Overflow[^] I installed System.Configuration.ConfigurationManager from Nuget into my .net core 2.2 application. I then reference using System.Configuration; Next, I changed WebConfigurationManager.AppSettings to .. ConfigurationManager.AppSettings

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups