Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting timeout errors with SqlTransaction on same table
    primarykey
    data
    text
    <pre><code>public TransImport() { ConnString = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString; SqlConnection conn_new; SqlCommand command_serial_new; SqlConnection conn; SqlCommand command_serial; SqlTransaction InsertUpdateSerialNumbers; conn = new SqlConnection(ConnString); command_serial = conn.CreateCommand(); conn_new = new SqlConnection(ConnString); command_serial_new = conn_new.CreateCommand(); command_serial_new.CommandText = "SELECT 1 FROM YSL00 WHERE SERLNMBR = @slnr"; var p = new SqlParameter("@slnr", SqlDbType.NVarChar, 50); command_serial_new.Parameters.Add(p); //Here you will start reading flat file to get serialnumber. InsertUpdateSerialNumbers = conn.BeginTransaction(); while (!headerFileReader.EndOfStream) { headerRow = headerFileReader.ReadLine(); if (CheckSerialNumber(headerFields[0].Trim())) DisplayMessage("Good serialnumber"); //this function is not copied here. } InsertUpdateSerialNumbers.Commit(); } private Boolean CheckSerialNumber(string SerialNumber) { command_serial_new.Parameters["@slnr"].Value = SerialNumber; try { var itExists = Convert.ToInt32(command_serial_new.ExecuteScalar()) &gt; 0; if (!itExists) { command_serial.Transaction = InsertUpdateSerialNumbers; command_serial.CommandText = "INSERT INTO YSL00([Manifest_Number],[PONUMBER],[ITEMNMBR],[SERLNMBR]" + "VALUES ('" + Manifest + "','" + PONr + "','" + itemNumber + "','" + serialNr + "')"; var insertStatus = command_serial.ExecuteNonQuery(); return true; } } catch (Exception ex) { LogException(ex, "Error in CheckSerialNumber =&gt;"+ command_serial_new.CommandText.ToString()); } return false; } </code></pre> <p>I get error "Timeout expired. The timeout period elapsed prior to completion of the operation or server is not responding".</p> <p>The CheckSerialNumber function also does an insert to YSL00 (the same table where I had executescalar. See code above). As I mentioned earlier there are 1000s of line in a flat file that I read and update YSL000 table. </p> <p>Note that I have two separate sqlcommands and also two separate connections to handle this. Reason is with sqltransaction it doesn't let me to query on the same table. I think timeout may be happening because of this?</p> <p>Thanks for reading. Please suggest</p> <p>Update 1: Since I have not pasted entire code, I want to mention that dispose is done using below code in the program.</p> <pre><code> if (conn != null) { conn.Close(); conn.Dispose(); } if (conn_new != null) { conn_new.Close(); conn_new.Dispose(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload