Showing all posts tagged: 'ADO.NET'

A 3-post collection

Using a dynamic DataReader with ADO.NET

I've recently had to do some data parsing, pulling data from a CSV file, performing some validation and then dumping a series of SQL commands for our data population scripts. I know there are a myriad ways to do this but I wanted to do this as quickly and easy as possible. The process is quite simple: Open the file using a StreamReader Use the awesome [CsvReader](" target="_blank) Map csv data to object ids from database Output SQL statements and error log To make things fast, I load all the necessary data …[read more]

Dealing with “Cannot drop database because it is currently in use” error in ADO.NET

Posted in ADO.NET

I’m a big fun of Entity Framework but every once a while I come across a case where EF is not adequate or the right tool for the job. In one such case, I had to implement some code to perform bulk inserts in order to improve performance. Shortly after I implemented the helper methods my unit tests started failing when attempting inside the tear down method which was responsible for clearing out the test data and deleting the test databases. The error? "Cannot drop database "7139e838-0de2-41b7-8b99-c0eb6a5b02c8" because it is currently in use." Below is …[read more]

An Object with the same key already exists in the ObjectStateManager, Entity Frawework

I have a generic repository which I use in my application to manage a large number of objects. I wrote the necessary unit tests to ensure that all methods work as expected and in isolation all was good. However, as soon as the application started implementing more complex operations, I came across the following error during updates: An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key.” In my controller I do something along these lines: Nothing unusual here. Move on, nothing to see. I fetch the existing user …[read more]