2 개의 다른 연결이 다른 SQL 서버, 원본 서버 및 대상 서버에 있습니다. 두 서버에있는 테이블을 비교하고 대상 서버 테이블을 원본 서버와 정렬하려고합니다.C#을 사용하는 2 개의 다른 sqlconnections가있는 1 개의 SQL
(select * from Source table) except (select * from Target table)
또는 둘 다 연결에서 테이블을 사용하는 다른 SQL 쿼리 :
SqlConnection src = (DataBaseConnection.GetSqlConnection());
SqlConnection trg = new SqlConnection(Properties.Settings.Default.IDCConnectionDEV);
src.Open();
trg.Open();
SqlCommand source = new SqlCommand("SELECT * FROM Source table", src);
SqlCommand traget = new SqlCommand("SELECT * FROM Target Table", trg);
SqlDataReader drsrc = source.ExecuteReader();
SqlDataReader drtrg = traget.ExecuteReader();
DataTable tbl1 = new DataTable();
tbl1.Load(drsrc);
DataTable tbl2 = new DataTable();
tbl2.Load(drtrg);
이제 내 질문에 내가 다음 쿼리를 실행합니까 방법이다.
서버는 서로 링크를 볼 수 있다면 sp_addlinkedserver를 사용하여 한 서버를 다른 서버에 연결하면 해당 서버가 두 번째 서버를 직접 쿼리 할 수 있습니다. ('select * from otherserver.dbname.dbo.sometable') –
또는 데이터를 읽은 다음 linq을 사용하여 데이터를 필터링하십시오 – Pikoh