Hi,
I am getting the above error on the last line:
MSSQLconnection.Close();
could you please help..
here is the code:
try
{
MSSQLconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSQL"].ConnectionString);
MSSQLconnection.Open();
MSSQLcommand = new SqlCommand("select * from persons where is_migrated = 0 order by file_no", MSSQLconnection);
MSSQLreader = MSSQLcommand.ExecuteReader();
while (MSSQLreader.Read())
{
lblFileNo.Text = "File# " + MSSQLreader["file_no"].ToString();
MySQL_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["mySQL"].ConnectionString);
MySQL_connection.Open();
MySQL_command = new MySqlCommand("insert into patients (current_file_no, id_type, id_number, date_of_birth, full_name, nationality, gender, old_file_no, marital_status, blood_group, patient_is_vip, is_outside_country, address_outside_address, address_country, address_flat, address_building, address_road, address_avenue, address_block, address_po_box, contact_mobile, contact_home_tel, personal_email, created_date) values (param_current_file_no, param_id_type, param_id_number, param_date_of_birth, param_full_name, param_nationality, param_gender, param_old_file_no, param_marital_status, param_blood_group, param_patient_is_vip, param_is_outside_country, param_address_outside_address, param_address_country, param_address_flat, param_address_building, param_address_road, param_address_avenue, param_address_block, param_address_po_box, param_contact_mobile, param_contact_home_tel, param_personal_email, param_created_date)", MySQL_connection);
MySQL_command.Parameters.Add("param_current_file_no", MySqlDbType.Int32).Value = Convert.ToInt32(MSSQLreader["file_no"]);
MySQL_command.Parameters.Add("param_id_type", MySqlDbType.VarChar, 255).Value = MSSQLreader["id_type"].ToString();
MySQL_command.Parameters.Add("param_id_number", MySqlDbType.VarChar, 255).Value = MSSQLreader["id_number"].ToString();
MySQL_command.Parameters.Add("param_date_of_birth", MySqlDbType.VarChar, 255).Value = MSSQLreader["date_of_birth"];
MySQL_command.Parameters.Add("param_full_name", MySqlDbType.VarChar, 255).Value = MSSQLreader["person_name"].ToString();
MySQL_command.Parameters.Add("param_nationality", MySqlDbType.VarChar, 255).Value = MSSQLreader["nationality"].ToString();
MySQL_command.Parameters.Add("param_gender", MySqlDbType.VarChar, 255).Value = MSSQLreader["gender"].ToString();
MySQL_command.Parameters.Add("param_old_file_no", MySqlDbType.VarChar, 255).Value = MSSQLreader["old_file_no"].ToString();
MySQL_command.Parameters.Add("param_marital_status", MySqlDbType.VarChar, 255).Value = MSSQLreader["marital_status"].ToString();
MySQL_command.Parameters.Add("param_blood_group", MySqlDbType.VarChar, 255).Value = MSSQLreader["blood_group"].ToString();
MySQL_command.Parameters.Add("param_patient_is_vip", MySqlDbType.VarChar, 255).Value = MSSQLreader["person_is_vip"].ToString();
MySQL_command.Parameters.Add("param_is_outside_country", MySqlDbType.VarChar, 255).Value = MSSQLreader["is_outside_country"].ToString();
MySQL_command.Parameters.Add("param_address_outside_address", MySqlDbType.VarChar, 255).Value = MSSQLreader["address_outside_address"];
MySQL_command.Parameters.Add("param_address_country", MySqlDbType.VarChar, 255).Value = MSSQLreader["address_country"].ToString();
MySQL_command.Parameters.Add("param_address_flat", MySqlDbType.VarChar, 255).Value = MSSQLreader["address_flat"];
MySQL_command.Parameters.Add("param_address_building", MySqlDbType.VarChar, 255).Value = MSSQLreader["address_building"];
MySQL_command.Parameters.Add("param_address_road", MySqlDbType.VarChar, 255).Value = MSSQLreader["address_road"];
MySQL_command.Parameters.Add("param_address_avenue", MySqlDbType.VarChar, 255).Value = MSSQLreader["address_avenue"];
MySQL_command.Parameters.Add("param_address_block", MySqlDbType.VarChar, 255).Value = MSSQLreader["address_block"];
MySQL_command.Parameters.Add("param_address_po_box", MySqlDbType.VarChar, 255).Value = MSSQLreader["address_po_box"];
MySQL_command.Parameters.Add("param_contact_mobile", MySqlDbType.VarChar, 255).Value = MSSQLreader["contact_moblle"];
MySQL_command.Parameters.Add("param_contact_home_tel", MySqlDbType.VarChar, 255).Value = MSSQLreader["contact_home_tel"];
MySQL_command.Parameters.Add("param_personal_email", MySqlDbType.VarChar, 255).Value = MSSQLreader["email_address"];
MySQL_command.Parameters.Add("param_created_date", MySqlDbType.Timestamp).Value = Convert.ToDateTime(MSSQLreader["created_date"]);
int MySQL_reader = MySQL_command.ExecuteNonQuery();
MySQL_command.Dispose();
MySQL_connection.Close();
mark_migrated(Convert.ToInt32(MSSQLreader["file_no"]));
}
}
catch (Exception exp)
{
return;
}
finally
{
MSSQLcommand.Dispose();
MSSQLreader.Close();
MSSQLconnection.Close();
}
|