darkdante darkdante - 8 days ago 5
C# Question

Multiple Insert transaction connection timeout - ADO.NET - SQL Server

I have a transaction with multiple inserts. All of the inserts work fine, except one.
I verified the parameters, the spelling, all of it, and it seems I'm not figuring it out.
It gives me the error:

Timeout expired. The timeout period elapsed prior to completion of the operation
or the server is not responding.


My transaction looks like this:

SqlConnection db = new SqlConnection(connString);
DataSet dataSet = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
using (db)
{
db.Open();
SqlTransaction trans = db.BeginTransaction();
try
{
//insert into COMMSignalDefinition !!Problem HERE
da.InsertCommand =
new SqlCommand("INSERT INTO COMMSignalDefinition(Name) "
+ "VALUES (@name)", db, trans);

da.InsertCommand.Parameters.Add("@name", SqlDbType.NVarChar);
foreach (DataRow row in ds.Tables["COMMTerminalSignal"].Select())
{
da.InsertCommand.Parameters[0].Value = row.ItemArray[1];
da.InsertCommand.ExecuteNonQuery();
}

// insert into COMMSignalExceptionDefinition -- names
da.InsertCommand =
new SqlCommand("INSERT INTO COMMSignalExceptionDefinition(Name) "
+ "VALUES (@name)", db, trans);
da.InsertCommand.Parameters.Add("@name", SqlDbType.NVarChar);
foreach (DataRow row in ds.Tables["COMMSignalExceptionDef"].Select())
{
da.InsertCommand.Parameters[0].Value = row.ItemArray[1];
da.InsertCommand.ExecuteNonQuery();
}

trans.Commit();
MessageBox.Show("You have successfully imported your Settings. "
+ "You can now exit the program.",
"Success",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
catch (Exception e)
{
trans.Rollback();
MessageBox.Show(e.Message,
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}


I have more inserts which work fine (I deleted the rest of them) and I moved the one with problems at the beginning.
My question is what could I possibly do wrong?
I even verified if the "problematic" query is sent to the server, with
SQL Server Profiler,
and it does! And if I execute it in
SQL Server Management studio
, it works too.

Connection Timeout
is set to 30

Can You please give me some leads ? SQL Server version is 2005 !
Thank You!

Answer

Please delete this post. I'm so ashamed of me... After hours of digging, it came out I did some tests in Management Studio, where I tested some transactions without committing them at all. So it was waiting for a commit, and I kept making, or trying to make inserts ... ! Shame on me ! Sorry about this.