Solved

ODBCDataReader to SQLDataReader

Posted on 2010-09-16
2
434 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now