If using Microsoft.Practices.EnterpriseLibrary it uses the web.config file to set the database configuration and connection. How would this work with MVC6 .Net Core/Vnext? To get this working? Does something need to be set on the Startup file??
Web.Config
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" />
</configSections>
<dataConfiguration defaultDatabase="MyDBConnectionString" />
<connectionStrings>
<add name="MyDBConnectionString" connectionString="Data Source=MyDatabaseServer;Database=MyDatabase; Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
</connectionStrings>
appsettings.json
{
"Data": {
"dataConfiguration": {
"type":"Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
"requirePermission": "false"
},
"DefaultConnection": {
"ConnectionString": "Data Source=MyDatabaseServer;Database=MyDatabase; Integrated Security=SSPI;",
"providerName": "System.Data.SqlClient"
}
},
Data Access
public static Model.Record GetRecordByID(Int32 ID)
{
//Declare the variables
Amendment obj = new Record();
object xml = null;
DbCommand dbCmd = null;
Database db = null;
try
{
// Create the database object, using the default database service. The
// default database service is determined through configuration.
DatabaseProviderFactory factory = new DatabaseProviderFactory(new SystemConfigurationSource());
DatabaseFactory.SetDatabaseProviderFactory(factory, false);
db = DatabaseFactory.CreateDatabase();
dbCmd = db.GetStoredProcCommand("spXMLGetRecordByID");
db.AddInParameter(dbCmd, "RecordID", DbType.Int32, ID);
db.AddInParameter(dbCmd, "@xml", DbType.Xml, 1);
if (!xml.Equals(DBNull.Value))
{
obj = (Amendment)Deserialize(xml.ToString(), typeof(Record));
}
}
catch (SqlException sqlEx)
{
// ExceptionUtility.SendError(sqlEx, "DAL", "GetRecordByID");
}
catch (Exception ex)
{
//ExceptionUtility.SendError(ex, "DAL", "GetRecordByID");
}
finally
{
// DALCleanUp(db, dbCmd);
}
return obj;
}