Need help advice
-
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
-
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
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
-
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
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
-
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
[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
-
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
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