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
Pradip Daingade
NA
226
20.6k
Cannot access a disposed object.
Nov 13 2013 7:42 AM
try { string strConn = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString.ToString(); SqlConnection con = new SqlConnection(strConn); FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftpserver"); request.Credentials = new NetworkCredential("username", "pass"); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Stream responsestream = response.GetResponseStream(); StreamReader sr = new StreamReader(responsestream); string line = sr.ReadLine(); string[] value = line.Split(','); DataTable dt = new DataTable(); DataRow row; foreach (string dc in value) { dt.Columns.Add(new DataColumn(dc)); } while (!sr.EndOfStream) { value = sr.ReadLine().Split(','); if (value.Length == dt.Columns.Count) { row = dt.NewRow(); row.ItemArray = value; dt.Rows.Add(row); } } SqlBulkCopy bc = new SqlBulkCopy(con.ConnectionString, SqlBulkCopyOptions.TableLock); bc.DestinationTableName = "CSVTest"; bc.BatchSize = dt.Rows.Count; con.Open(); bc.WriteToServer(dt); bc.Close(); con.Close(); sr.Close(); sr.Dispose(); //File.Open(str1, FileMode.Open, FileAccess.Read, FileShare.None); using (var writer = new StreamWriter(responsestream)) { writer.Write(""); } } catch (ObjectDisposedException a) { Console.WriteLine("Caught: {0}", a.Message); } finally { } read complete text file after complete read while loop get error Cannot access a disposed object. Object name: 'System.Net.Sockets.NetworkStream'.
Reply
Answers (
7
)
parameter
C# Video Downloader with HTML tag