Hi,
I'm working on my first .Net DataStore Web Api project and it is really different from PBScript. On DB Server we have many databases (same structure) for different customers (tenants) and I would like to send the database name via HTTP header like:
inv_RESTClient.SetRequestHeader("DbName", "MyDbName")
How can I handle this on Web Api project?
Today I have a appsettings.json:
{
"ConnectionStrings": {
"Test": "Data Source=SRVDB,1433;Initial Catalog=MyDb;Integrated Security=False;User ID=sa;Password=adm;Pooling=True;Min Pool Size=0;Max Pool Size=100;MultipleActiveResultSets=False;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite"
}
}
and the TestDataContext.cs:
using SnapObjects.Data;
using SnapObjects.Data.SqlServer;
namespace Test
{
public class TestDataContext : SqlServerDataContext
{
public TestDataContext(string connectionString)
: this(new SqlServerDataContextOptions<TestDataContext>(connectionString))
{
}
public TestDataContext(IDataContextOptions<TestDataContext> options)
: base(options)
{
}
public TestDataContext(IDataContextOptions options)
: base(options)
{
}
}
}
and startup.cs:
...
namespace Test
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers(m =>
{
m.UseCoreIntegrated();
m.UsePowerBuilderIntegrated(); //add UsePowerBuilderIntegrated
});
// Original AddDataContext
//services.AddDataContext<TestDataContext>(m => m.UseSqlServer(this.Configuration, "Test"));
// Actual AddDataContext
string DbName = "MyDbName"; // ==>> I would like to get de HTTP Request Header "DbName" at this point
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(Configuration.GetConnectionString("Test"));
builder.InitialCatalog = DbName;
services.AddDataContext<TestDataContext>(m => m.UseSqlServer(builder.ConnectionString));
...
Thanks.
Marcos
PB 2019 R3 Build 2670