Re: Transaction across multiple SqlMapConfig
Serge, In the case from this article, you're controlling the connection, ensuring only one connection is made, so yes, I think that can work if you're making ADO.NET calls directly. If you're using IBatis DataMapper, when you open a connection with something like ISqlMapSession session = sqlMap.OpenConnection(), the session is tied to a certain instance of ISqlMapper, which in turn, is tied to a particular SqlMapConfig. If you want to query with a different SqlMapConfig, you're going to need to use a different instance of ISqlMapper which isn't going to be able to participate in a session created by the first ISqlMapper instance. Here's some code to illustrate: using(TransactionScope scope = new TransactionScope()) { using(ISqlMapSession session = sqlMap1.OpenConnection()) { sqlMap1.Insert(someStatement, parameter1); // The second ISqlMapper isn't participating in the session / connection created by sqlMap1. sqlMap2.Insert(someOtherStatement, parameter2); } scope.Complete(); } Since sqlMap2 here isn't participating in the same session, sqlMap2 is going to open a new database connection to execute someOtherStatement so if both statements are executed within a TransactionScope on SQL Server 2005 with .NET 2.0, this will promote the transaction. I wish it would work in older versions of .NET. The TransactionScope should be smart enough to realize it's able to get a connection from the same connection pool and shouldn't promote it, but it didn't get this smart until .NET 3.5 and the ADO.NETdriver for SQL Server 2008, unfortunately. Hope that's helpful, Dave On Sun, Apr 4, 2010 at 10:04 PM, Serge Boulay serge.bou...@gmail.comwrote: I suspect this would also work with .net 2.0 and sql server 2005. http://davidhayden.com/blog/dave/archive/2005/12/09/2615.aspx
Transaction across multiple SqlMapConfig
Hello, first of all I want to apologize for my bad english, I'll try to do my best. I have a problem and I can't work out the solution. My application is divided in modules and for designing propuses every module has it's own SqlMapConfig and Mapper. The application is composed by Core + Modules. Every module is in a .DLL Everything works fine except when it comes to transactions. Even if all the SqlMapConfig shares the same conection string transactions are not working properly. Every DAO created is seen as a separate conection. The escanario is the following: OpenTransaction Core Insert into core object A Insert into core object B Insert into Module 1 object C Insert into Module 2 object e commit Core transaction When I get to the line code: Insert into Module 1 object C I get a connection timeout. That is because my transaction level is Serializable and the database is expecting that the Transaction Core finishes before doing something else. Ibatis is not seein both Mapper as the same connection. Any ideas how I do that? As a global idea I need transactions over DAO loaded by diferents SqlMaps pointing to the same db. hope I make everythying clear. I would appreciate a lot any advice you can give me. regards, jose -- View this message in context: http://old.nabble.com/Transaction-across-multiple-SqlMapConfig-tp28000351p28000351.html Sent from the iBATIS - User - Cs mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-cs-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-cs-h...@ibatis.apache.org
Re: Transaction across multiple SqlMapConfig
What I currently do Jose is use the Castle framework and use its Transaction package. I currently span transactions across Oracle, SQL Server, and Teradata. You can find it here: http://www.castleproject.org/ On Tue, Mar 23, 2010 at 5:51 AM, jozeibatis jose.granja.marti...@gmail.comwrote: Hello, first of all I want to apologize for my bad english, I'll try to do my best. I have a problem and I can't work out the solution. My application is divided in modules and for designing propuses every module has it's own SqlMapConfig and Mapper. The application is composed by Core + Modules. Every module is in a .DLL Everything works fine except when it comes to transactions. Even if all the SqlMapConfig shares the same conection string transactions are not working properly. Every DAO created is seen as a separate conection. The escanario is the following: OpenTransaction Core Insert into core object A Insert into core object B Insert into Module 1 object C Insert into Module 2 object e commit Core transaction When I get to the line code: Insert into Module 1 object C I get a connection timeout. That is because my transaction level is Serializable and the database is expecting that the Transaction Core finishes before doing something else. Ibatis is not seein both Mapper as the same connection. Any ideas how I do that? As a global idea I need transactions over DAO loaded by diferents SqlMaps pointing to the same db. hope I make everythying clear. I would appreciate a lot any advice you can give me. regards, jose -- View this message in context: http://old.nabble.com/Transaction-across-multiple-SqlMapConfig-tp28000351p28000351.html Sent from the iBATIS - User - Cs mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-cs-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-cs-h...@ibatis.apache.org -- Michael J. McCurrey Read with me at http://www.mccurrey.com http://chaoticmindramblings.blogspot.com/
Re: Transaction across multiple SqlMapConfig
Hi! Thanks for the advice! I've been looking to Castle and Ibatis has also Transaction Scope hasn't it? What my gol is that both Mapper share the datasource, so they're seen as one by the db. I'm not happy using transaction global because it would be slower than both DAO seen as the same :S I hope u understand me, I have trouble beeing precie in English Michael McCurrey-3 wrote: What I currently do Jose is use the Castle framework and use its Transaction package. I currently span transactions across Oracle, SQL Server, and Teradata. You can find it here: http://www.castleproject.org/ On Tue, Mar 23, 2010 at 5:51 AM, jozeibatis jose.granja.marti...@gmail.comwrote: Hello, first of all I want to apologize for my bad english, I'll try to do my best. I have a problem and I can't work out the solution. My application is divided in modules and for designing propuses every module has it's own SqlMapConfig and Mapper. The application is composed by Core + Modules. Every module is in a .DLL Everything works fine except when it comes to transactions. Even if all the SqlMapConfig shares the same conection string transactions are not working properly. Every DAO created is seen as a separate conection. The escanario is the following: OpenTransaction Core Insert into core object A Insert into core object B Insert into Module 1 object C Insert into Module 2 object e commit Core transaction When I get to the line code: Insert into Module 1 object C I get a connection timeout. That is because my transaction level is Serializable and the database is expecting that the Transaction Core finishes before doing something else. Ibatis is not seein both Mapper as the same connection. Any ideas how I do that? As a global idea I need transactions over DAO loaded by diferents SqlMaps pointing to the same db. hope I make everythying clear. I would appreciate a lot any advice you can give me. regards, jose -- View this message in context: http://old.nabble.com/Transaction-across-multiple-SqlMapConfig-tp28000351p28000351.html Sent from the iBATIS - User - Cs mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-cs-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-cs-h...@ibatis.apache.org -- Michael J. McCurrey Read with me at http://www.mccurrey.com http://chaoticmindramblings.blogspot.com/ -- View this message in context: http://old.nabble.com/Transaction-across-multiple-SqlMapConfig-tp28000351p28001144.html Sent from the iBATIS - User - Cs mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-cs-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-cs-h...@ibatis.apache.org
Re: Transaction across multiple SqlMapConfig
Not knowing what your environment is, this may or may not be useful to you. Using .NET 3.5 and SQL Server 2008, when you execute multiple statements using the same connection pool (same string) and within the same TransactionScope, the transaction will remain lightweight. It is only promoted to a distributed transaction if you use a different connection string. This was a big difference from .NET 2.0 and older versions of SQL Server and has allowed me to use a TransactionScope more effectively. using(TransactionScope scope = new TransactionScope()) { // Multiple DataMapper calls can occur here using different mapping files // as long as they use the same connection string. } Read details about it in the section titled Promotable Transactions in SQL Server 2008 here: http://msdn.microsoft.com/en-us/library/ms172070.aspx Again, if you're not able to use .NET 3.5 or SQL Server 2008, I'm afraid this won't be helpful, but I just wanted to make you aware of it in case that is an option for you. On Tue, Mar 23, 2010 at 9:47 AM, jozeibatis jose.granja.marti...@gmail.comwrote: Hi! Thanks for the advice! I've been looking to Castle and Ibatis has also Transaction Scope hasn't it? What my gol is that both Mapper share the datasource, so they're seen as one by the db. I'm not happy using transaction global because it would be slower than both DAO seen as the same :S I hope u understand me, I have trouble beeing precie in English Michael McCurrey-3 wrote: What I currently do Jose is use the Castle framework and use its Transaction package. I currently span transactions across Oracle, SQL Server, and Teradata. You can find it here: http://www.castleproject.org/ On Tue, Mar 23, 2010 at 5:51 AM, jozeibatis jose.granja.marti...@gmail.comwrote: Hello, first of all I want to apologize for my bad english, I'll try to do my best. I have a problem and I can't work out the solution. My application is divided in modules and for designing propuses every module has it's own SqlMapConfig and Mapper. The application is composed by Core + Modules. Every module is in a .DLL Everything works fine except when it comes to transactions. Even if all the SqlMapConfig shares the same conection string transactions are not working properly. Every DAO created is seen as a separate conection. The escanario is the following: OpenTransaction Core Insert into core object A Insert into core object B Insert into Module 1 object C Insert into Module 2 object e commit Core transaction When I get to the line code: Insert into Module 1 object C I get a connection timeout. That is because my transaction level is Serializable and the database is expecting that the Transaction Core finishes before doing something else. Ibatis is not seein both Mapper as the same connection. Any ideas how I do that? As a global idea I need transactions over DAO loaded by diferents SqlMaps pointing to the same db. hope I make everythying clear. I would appreciate a lot any advice you can give me. regards, jose -- View this message in context: http://old.nabble.com/Transaction-across-multiple-SqlMapConfig-tp28000351p28000351.html Sent from the iBATIS - User - Cs mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-cs-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-cs-h...@ibatis.apache.org -- Michael J. McCurrey Read with me at http://www.mccurrey.com http://chaoticmindramblings.blogspot.com/ -- View this message in context: http://old.nabble.com/Transaction-across-multiple-SqlMapConfig-tp28000351p28001144.html Sent from the iBATIS - User - Cs mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-cs-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-cs-h...@ibatis.apache.org
Re: Transaction across multiple SqlMapConfig
Thank for the reply! I was using using (TransactionScope tx = new TransactionScope()) but somehow the data is not commited once inserted! Everything seems to work fine but after I realise that nothing has been inserted on the database! I think it's no commiting anything and the data gets lost! Any ideas? I really apreciat your help :) -- View this message in context: http://old.nabble.com/Transaction-across-multiple-SqlMapConfig-tp28000351p28003565.html Sent from the iBATIS - User - Cs mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-cs-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-cs-h...@ibatis.apache.org
Re: Transaction across multiple SqlMapConfig
ok! I wasn't commiting anything! using tx.Complete(); solved the problem :)) -- View this message in context: http://old.nabble.com/Transaction-across-multiple-SqlMapConfig-tp28000351p28003684.html Sent from the iBATIS - User - Cs mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-cs-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-cs-h...@ibatis.apache.org