Click here to Skip to main content
15,173,818 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)

I have two SQl Server Databases(Customer, Quotes) on the same server. I am building a winform that has several textboxes,comboboxes, checkboxes that is used to enter data into the quote db, It also has one textbox that is used to search the Customer(Id) db for a customer name. Once i find the particular customer i would like to add a newly created Quotes(CustomerId) against that Customer.

My question how could i marry the two together, using sql or entity framework.

An example of what im trying to do.
Enter Quote Data:
Product : Shoes
Quantity : 20
Search Customer db ........ Joe Bloggs Id 123
Found Customer ;
Insert Customer id and Quote info into Quote table on seperate db.

What I have tried:

Im able to query the Customer db to search for a customer.And seperately im able to insert data into Quotes db.
Updated 30-Jun-16 6:50am
Tomas Takac 30-Jun-16 6:44am
Just to make sure. Are you asking about how to do the two inserts in the same transaction?
BEBE2011 30-Jun-16 6:53am
Hi, Thanks for the reply, i edited my question, to try an make it clerer.
Kuthuparakkal 30-Jun-16 7:16am
We may need a database priest to conduct this marriage....
G3Coder 30-Jun-16 8:12am
Maybe if you explained what you mean by "marry"?
There will no easy referential integrity across the two separate databases, and if you want such a single database is the way forward. If not - just insert the data into the second database.
BEBE2011 30-Jun-16 8:41am
Sorry , i see know what i have done "Marry" was the wrong word to use.How can i query one db and insert into another db, uwhile passing in the id of the queried db.
Jim_Snyder 30-Jun-16 9:41am
For the second database, you need a fully qualified path.

1 solution

It's easy just create two connection strings.


public int GetId(){
using (SqlConnection con = new SqlConnection("CONNECTION STRING TO CUSTOMER DB")
 //logic to get id
public void Save(int customerId, object Quote){
using (SqlConnection con = new SqlConnection("CONNECTION STRING TO QUOTE DB")
 //logic to save quote with customer id

If you need to do it in transaction I recommend you to read some articles about that.
A Beginner's Tutorial for Understanding Transactions and TransactionScope in ADO.NET[^]

You are interested in distributed transactions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900