0

I have an application that runs multiple concurrent background processes to insert data into the database using the Enterprise Library's Data Access application block. Each of the background thread uses the DatabaseFactory.CreateDatabase passing in the same database instance name. The following is the snippet of code that retrieves the database and command object:

Microsoft.Practices.EnterpriseLibrary.Data.Database database = DatabaseFactory.CreateDatabase(this.DatabaseInstanceName);
DbCommand commandObj = database.GetSqlStringCommand(statement);

I'm finding that this is not thread safe and I'm getting errors due to the values getting mixed up across the threads. How should I handle this to ensure that it is thread safe?

thanks in advance!

ptn77
  • 567
  • 3
  • 8
  • 23

1 Answers1

1

I found my issue. The values that were getting mixed up across threads were not due to the Enterprise Library Data Access objects but another object I used to store parameters. I had accidentally made it global instead of a local resource within each thread.

ptn77
  • 567
  • 3
  • 8
  • 23