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?

3
  • 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. Commented Jun 4, 2021 at 14:19
  • does this answer help you? stackoverflow.com/a/58123708/1366179 and is the question of that answer what you're trying to accomplish? Commented Jun 4, 2021 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. Commented Jun 7, 2021 at 5:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.