0

I have a task ahead of me that requires the use of local temporary tables. For performance reasons I can't use transactions.

Temporary tables much like transactions require that all queries must come from one connection which must not be closed or reset. How can I accomplish this using Enterprise library data access application block?

Nezreli
  • 1,278
  • 4
  • 16
  • 34
  • Do you mean that you want to manipulate data in temporary tables that are on the server through DAAB? Can you not manipulate the data client-side? – Rikalous Sep 30 '13 at 14:36
  • Yes, all queries would have to go through DAAB. For performance reasons sometimes it's not practical to do client side data manipulation. These are rare cases but they do exist. – Nezreli Sep 30 '13 at 15:33

2 Answers2

1

Enterprise Library will use a single database connection if a transaction is active. However, there is no way to force a single connection for all Database methods in the absence of a transaction.

You can definitely use the Database.CreateConnection method to get a database connection. You could then use that connection along with the DbCommand objects to perform the appropriate logic.

Other approaches would be to modify Enterprise Library source code to do exactly what you want or create a new Database implementation that does not perform connection management.

Randy Levy
  • 22,566
  • 4
  • 68
  • 94
  • The source code for method Database.ExecuteNonQuery(DbCommand) indicates that DAAB will always open a new connection regardless if command has one already so I'm not sure what would method CreateConnection accomplish. – Nezreli Sep 30 '13 at 15:46
  • You call `CreateConnection` and then you hold on to that connection and use it for as long as you need it. – Randy Levy Sep 30 '13 at 16:36
  • That means that I can't use Database.Execute* methods because they create they own connection. What do I lose by doing this? – Nezreli Oct 01 '13 at 07:31
  • 1
    Yes, as I say you will need to use DbCommand objects directly (and can't use the Execute* methods). You can use other helper methods such as AddParameter. – Randy Levy Oct 01 '13 at 13:52
  • Thanks. This will do I suppose. – Nezreli Oct 02 '13 at 07:15
0

Can't see a way of doing that with DAAB. I think you are going to have to drop back to use ADO.Net connections and manage them yourself, but even then, playing with temporary tables on the server from a client-side app doesn't strike me as an optimal solution to a problem.

Rikalous
  • 4,514
  • 1
  • 40
  • 52