Solved

ODBCDataReader to SQLDataReader

Posted on 2010-09-16
2
458 Views
Last Modified: 2012-05-10
I have an older .Net Windows Service that I am converting.  The Service polls ISAM files and gets the latest records.  The Service creates an ODBCDataReader for reading the ISAM files.

The conversion requires that I read the ISAM files and then write the resulting dataset to SQL Server.

Once I have the ODBCDataReader filled, then is there an easy way to write this data to a SQL Server 2005 database.  Currently the application is using a very long ConvertDataReadertoDataSet function that is timing out some service running on the Linux box.    I don't have any control over the Linux box so I have to make this work from my end.  

I have attached the function that is being used that is timing out the service.  The column count is 45 which is chewing up time ConvertDataReaderToDataSe1t.txt
0
Comment
Question by:sherbug1015
2 Comments
 
LVL 28

Accepted Solution

by:
strickdd earned 500 total points
ID: 33700426
The basic idea would be to loop through the data reader and call a store proc. The code i posted is in C#, but it should be easy enough to convert.
SqlConnection conn = new SqlConnection(myConnString);
SqlCommand cmd = new SqlCommand("StoreProcName", conn);

conn.Open();

for( int i = 1; i<isamReader.Length; i++)
{
   cmd.Parameters.AddWithValue("@ParamName1", isamReader["Field1"].ToString()); //Probably should check for DBNull.Value before converting to string, you should also convert to the correct data type
   cmd.Parameters.AddWithValue("@ParamName2", isamReader["Field2"].ToString());
   .
   .
   .
   cmd.Parameters.AddWithValue("@ParamNameN", isamReader["FieldN"].ToString());

   cmd.ExecuteNonQuery();
   cmd.Parameters.Clear();
}

conn.Close

Open in new window

0
 

Author Comment

by:sherbug1015
ID: 33701182
That looks a lot cleaner than that other one.  Thank you.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question