0

I have a two databases in place. One will be used to collect survey data while the other contains data from "clients". On the web form, the client is to input he's/her policy number. I would like to validate the data that will be input to ensure only existing clients fill in the form:

I have already configured my appsettings.json and Startup.cs as below:

{
"ConnectionStrings": {
"DefaultConnection": "Data Source=yyyy.yy;Initial Catalog=Mydb;Integrated Security=True",
"IPAC": "Server=xxx.xx.xx;Database=50_TEST;UID=user;Password=password"
}

Startup.cs

Configuration.GetConnectionString("DefaultConnection")))
  .AddDbContext<ApplicationDbContext>(options =>
  options.UseSqlServer(Configuration.GetConnectionString("IPAC")));

Assuming that my form only accepts the PolicyNo field, how do I go about ensuring that this works?

Nickson
  • 135
  • 12
  • This is the perfect work for a foreign key...... if they were in the same DB :D. Since you have two separate databases, potentially on different servers, there is no choice but to query in the clients db for the entered policy number, error out if not found, then insert the data in the survey DB, under a different connection. – Alejandro Jun 04 '21 at 14:19
  • does this answer help you? https://stackoverflow.com/a/58123708/1366179 and is the question of that answer what you're trying to accomplish? – Brett Caswell Jun 04 '21 at 14:49
  • From your description, one database stores the user information (contains the Policy Number), when user login, you could access this database to validate the user and get the Policy Number. In another database, when you store the survey, you can add the Policy Number property, after user login successfully, you can access this database and find the survey based on the policy number. In above method, you should register two db context with different connection. – Zhi Lv Jun 07 '21 at 05:50

0 Answers0