TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Najjaf Shuja
NA
31
1.2k
Timeout expired.
Jun 4 2015 4:19 AM
Hello Guys,
I am developing DataMigration Utility in which I am migrating Data from one database to another by writing simple queries using SQLCommand, Datatable, ExecuteReader etc.
I am using TransactionScope which I set timeout for 1 hour and 30 seconds.
using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, new System.TimeSpan(1, 30, 0)))
Now I am copying data from one table which has 16051721 rows. I am getting data in chunks and inserting it through ExecuteNonQuery().
Problem is after sometime it is throwing exception,
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated.
Sample code is below,
foreach (string id in idList)
{
query = "SELECT * FROM table1 where fk_id = " + id;
myCommand = new SqlCommand(query, source);
dt = null;
dt = new DataTable();
dt.Load(myCommand.ExecuteReader());
qExpre = string.Empty;
if (dt.Rows.Count > 0)
{
foreach (DataRow row in dt.Rows)
{
qExpre += " insert into destinationTable
values('" + row["fk_id"] + "', 'A', '" + row["ID"] + "', '" + Guid.NewGuid() + "', " + row["distance"] + ", " + row["unit"] + ", " + row["name"] + ", 'Migrated Data', '" + DateTime.Now + "')";
}
if (!string.IsNullOrEmpty(qExpre))
{
myCommand = new SqlCommand(qExpre, destination);
myCommand.ExecuteNonQuery();
}
}
}
}
Reply
Answers (
6
)
how can use Superscript Or Subscript in sql server
How to make my sqlserver to strong