guray uysal

guray uysal

  • NA
  • 4
  • 0

Data transfer between different servers

Sep 6 2011 11:48 AM
SqlCommand cmd = new SqlCommand("SELECT (DEPOFISID+20000)*-1 AS DEPOFISID,[TARIH],'ELEKTRA' AS [YETKILI],[ISLEM],[ENO],'BEACH AKTARIM' AS [ACIKLAMA],[GDEPOID],[CDEPOID],[TADET],[TTUTAR],[GSKODU],[CSKODU],[URUNFISID],[URETILDI],[LOGOAKTAR],[LOGODANGELDI],[ISLEMDETAY],[SDEPART],[ONAY],[MUHFISID],[DURUMU],[SUBEID],[EK1],[EK2],[USERID],[DURUM],[MUHFC] FROM DEPOFIS WHERE 1=1 AND '" + string.Format("{0:MM/dd/yyyy}", islema_batarih.EditValue) + "'<=TARIH AND '" + string.Format("{0:MM/dd/yyyy}", islema_bitarih.EditValue) + "'>=TARIH", DBCONNECTION.Sql_Connection.DB_CONNECTB());
SqlCommand cmd_isl = new SqlCommand("SELECT [DEPOFISISLID],(DEPOFISID+20000)*-1 AS DEPOFISID,[STOKID],[MIKTAR],[FBIRIM],[FMIKTAR],[BFIYAT],[SFIYAT],[YETKILI],[ACIKLAMA],[MARKAID],[ISLREFID],[FBFIYAT],[URETSEVIYE],[SATINALMAISLID],[BARKOD],[SKTARIHI],[RGDEPOID],[RCDEPOID],[SARFDEPOID]  FROM DEPOFISISL WHERE 1=1 AND  DEPOFISID IN(SELECT DEPOFISID FROM DEPOFIS WHERE 1=1 AND '" + string.Format("{0:MM/dd/yyyy}", islema_batarih.EditValue) + "'<=TARIH AND '" + string.Format("{0:MM/dd/yyyy}", islema_bitarih.EditValue) + "'>=TARIH)", DBCONNECTION.Sql_Connection.DB_CONNECTB());

//Transaction Kontrol Islemini Baslat
 
  cmd.Transaction = trans;
  cmd_isl.Transaction = trans_isl;
 
  trans = DBCONNECTION.Sql_Connection.DB_CONNECTB().BeginTransaction();
  trans_isl = DBCONNECTION.Sql_Connection.DB_CONNECTB().BeginTransaction();

  SqlDataReader reader = cmd.ExecuteReader(); >>>>>>>>>>ERROR LINE

  SqlBulkCopy copydata = new   SqlBulkCopy(DBCONNECTION.Sql_Connection.DB_CONNECTM());

  SqlDataReader reader_isl = cmd_isl.ExecuteReader();
  SqlBulkCopy copydata_isl = new SqlBulkCopy(DBCONNECTION.Sql_Connection.DB_CONNECTM());

  copydata.DestinationTableName = "DEPOFIS";
  copydata.NotifyAfter = 500;
  copydata.WriteToServer(reader);
                 
  copydata_isl.DestinationTableName = "DEPOFISISL";
  copydata.NotifyAfter = 500;
  copydata_isl.WriteToServer(reader_isl);

 //Transaction Kontrol Noktasi Olustur

   trans.Save("Start");
   trans_isl.Save("Start");

   copydata.Close();
   copydata_isl.Close();       


Above code part is under a button click event.It works correctly.But When I changed the date parameter and click second time on button I get this error "The transaction is either not associated with the current connection or has been completed." Error line shown >>>>>>>> above.What should I do? Thanks for your helps...

Answers (3)