1

I'm trying to read BLOB data from an SQL table into variables using the SqlDataReader.

The strange thing is, this exception occurs every time after about 2800 rows. I've already excluded the row in question, but apparently this is not due to the row itself, rather than the overall amount of rows (or bytes).

The exception:

A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 19 - Physical connection is not usable)

My code:

string command = string.Format("SELECT * FROM (select *, ntile({0}) over(order by Id) as SplitNumber from BLOB) T1 WHERE SplitNumber = {1}", _maxThreadCount - (Environment.ProcessorCount * 2) + 1, splitNumber);

        using (SqlConnection sqlConnection = new SqlConnection(SourceConnectionString))
        {
            sqlConnection.Open();

            using (SqlCommand sqlCommand = new SqlCommand(command, sqlConnection))
            {
                using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
                {
                    if (sqlDataReader.HasRows)
                    {                            
                        while (sqlDataReader.Read())
                        {
                            try
                            {
                                byte[] blob = (byte[])sqlDataReader["Blob"];

                        [.......]

The exception occurs exactly on byte[] blob = (byte[])sqlDataReader["Blob"]; and I can't imagine why this is happening.

Any thoughts?

3
  • Two questions: 1- What kind of data are you storing in your database and why aren't you storing them as files instead? 2- What's the average size in bytes of the blob you're storing? I'm assuming It's a SQL Timeout issue while getting the blob Data Commented Dec 23, 2013 at 11:24
  • What connection string are you using? Anyone/thing else using the database? Single threaded? Commented Dec 23, 2013 at 11:26
  • I'm the only one using the database. It startet off being multithreaded, but it's now running on a single thread due to my thinking it could have had something to do with that. Which kind of information do you need to know from my connectionstring? Edit: I believe it's good to know that I'm connecting to a locally installed SQL Server. Commented Dec 23, 2013 at 11:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.