Solved

ODBCDataReader to SQLDataReader

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 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