Any Idea why this code SqlCommand ExecuteNonQuery Throws StackOverFlowException
I have no idea why this code always throws StackOverflowExeption, please take a look, this is the source script
1DROP TABLEtrantest1
2DROP TABLEtrantest2
3CREATE TABLEtrantest1 (idint identity(1000,1), messagenvarchar(1000))
4CREATE TABLEtrantest2 (idint identity(1000,1), messagenvarchar(1000))
5 GO
6DROP PROCusp_insert_message1;
7 GO
8CREATE PROCusp_insert_message1 @messagenvarchar(200)AS
9INSERT INTOtrantest1VALUES(@message);
10 GO
11DROP PROCusp_insert_message2;
12 GO
13CREATE PROCusp_insert_message2 @messagenvarchar(200)AS
14INSERT INTOtrantest2VALUES(@message);
15 GO
16SELECT*FROMtrantest1
17SELECT*FROMtrantest2
This is the test codes:
1publicclassTestBLL {
2
3publicvoid InsertMessages() {
4IDataAccessAdapter adapter =newSqlDataAdapter();
5
6try {
7 adapter.KeepConnectionAlive =true;
8 adapter.StartTransaction(IsolationLevel.ReadCommitted,"InsertMessage");
9
10TestMapper mapper1 =newTestMapper(adapter);
11 mapper1.InsertMessage1("first message");
12
13TestMapper mapper2 =newTestMapper(adapter);
14 mapper2.InsertMessage2("second message");
15
16 adapter.Commit();
17 }catch(Exception){
18 adapter.Rollback();
19 }finally {
20 adapter.Dispose();
21 }
22 }
23 }
1publicclassTestMapper :MapperBase {
2
3 #region constructors
4public TestMapper() :base() { }
5
6public TestMapper(string connectionString) :base(connectionString) { }
7
8public TestMapper(IDataAccessAdapter adapterToUse) :base(adapterToUse) { }
9 #endregion
10
11publicint InsertMessage1(string message) {
12int affectedRecords = 0;
13
14using (SqlConnection connection = Adapter.GetActiveConnection<SqlConnection>()) {
15SqlCommand command =newSqlCommand("usp_insert_message1", connection);
16 command.CommandType =CommandType.StoredProcedure;
17 command.Parameters.AddWithValue("@message", message);
18
19 Adapter.OpenConnection();
20 command.ExecuteNonQuery();//<<-- stackoverflow exception thrown here
21 }return affectedRecords;
22 }
23
24
25publicint InsertMessage2(string message) {
26int affectedRecords = 0;
27
28using (SqlConnection connection = Adapter.GetActiveConnection<SqlConnection>()) {
29SqlCommand command =newSqlCommand("usp_insert_message2", connection);
30 command.CommandType =CommandType.StoredProcedure;
31 command.Parameters.AddWithValue("@message", message);
32
33 Adapter.OpenConnection();
34 command.ExecuteNonQuery();//<<-- never called because of exception
35 }return affectedRecords;
36 }
37
38 }
I tried executing the script on QA and it works fine but when using SqlCommand, it throws that exception on ExecuteNonQuery
TIA!

