SqlDataAdapter - Internal connection fatal error.

I have a stored procedure that returns a set of data (screen shot below).  When I call the procedure from my code and try to load a dataset using the SqlDataAdapter I get an "Internal connection fatal error".  I was able to narrow it down to one value in the hours_worked column (highlighted in the image).   This columns data type is a numeric(6,3).  A value of .100 does not cause an issue.  Why does a value of .05 or any value of .0xx cause the SqlDataAdapter to throw an "Internal connection fatal error"?  How do I get around this problem?  I tried casting the value to a varchar and that did not work.

result set
axnst2Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
Are you filling an existing datatable or a new dataset?

If it's an existing object it could be a type mismatch.

What if you do a full cast on the numeric in your stored procedure
eg:
select ...., cast (hours_worked as numeric(18,3)) hours_worked from table

Open in new window

axnst2Author Commented:
Hi Kyle - I tried your suggestion and I still get the same error.   To answer your second question, this is a new object also.

Here is the stack trace if that helps.

  at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlDataReader.TryHasMoreResults(Boolean& moreResults)
   at System.Data.SqlClient.SqlDataReader.TryNextResult(Boolean& more)
   at System.Data.SqlClient.SqlDataReader.NextResult()
   at System.Data.ProviderBase.DataReaderContainer.NextResult()
   at System.Data.Common.DataAdapter.FillNextResult(DataReaderContainer dataReader)
   at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
   at System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
   at PPG.AC.NA.SS.DBAccess.SQLDatabase.ExecuteStoredProcedureWithReturn(String SQLCommand) in c:\projects\ppg\PAC_Store_Systems\New Store System\PPG.AC.NA.SS.DBAccess\SQLDatabase.cs:line 301
Kyle AbrahamsSenior .Net DeveloperCommented:
Can you post your code for the call?  (you can hide actual connection strings)
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

axnst2Author Commented:
I don't think the issue is not related to the code making the call.  I can run the same code for another week and have no issues.

public DataSet ExecuteStoredProcedureWithReturn(String SQLCommand)
        {
            // Make sure the command exists
            if (SQLCommand == null)
            {
                throw new Exception("Can't execute stored procedure. Command object was never instantiated.");
            }

            // Make sure the command has been set
            if (SQLCommand == "")
            {
                throw new Exception("Can't execute stored procedure. Stored procedure name is missing.");
            }

            NamedSQLConnection sqlConnection = _connectionPool.FetchConnection();

            if (sqlConnection == null || sqlConnection.Connection.State != ConnectionState.Open)
                throw new Exception("DB connection not open");

            try
            {
                lock (_dataReaderLock)
                {
                    SqlCommand command = new SqlCommand(SQLCommand, sqlConnection.Connection);

                    // Now actually execute the stored procedure
                    command.CommandText = SQLCommand;

                    //command.Connection = sqlConn;

                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.Clear();

                    SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
                    dataAdapter.MissingMappingAction = MissingMappingAction.Passthrough;

                    dataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

                    DataSet dataSet = new DataSet();

                    // If the stored procedure requires input/output parameters
                    if (!(_parameterList == null))
                    {
                        for (int counter = 0; counter < _parameterList.Length; counter++)
                        {
                            command.Parameters.Add(_parameterList[counter]);
                        }

                        dataAdapter.Fill(dataSet);

                        _logger.Info("Succefully executed script '" + SQLCommand + "'");
                    }

                    //Let's dispose of the command
                    command.Dispose();

                    dataAdapter.Dispose();

                    return dataSet;
                }
            }
            catch (Exception er)
            {
                _logger.Debug("Error while attempting to execute '" + SQLCommand + "'");
                throw er;
            }
            finally
            {
                _connectionPool.ReturnConnection(sqlConnection);
            }

            #region Implementation Example

            //List<SqlParameter> sqlParamList = new List<SqlParameter>();

            //SqlParameter[] parameterArray = new SqlParameter[2];

            //parameterArray[0] = new SqlParameter("@MaxScheduleNum", newMaxSchedNum);
            //parameterArray[1] = new SqlParameter("@UserName", userName);

            //sqlParamList.Clear();

            //sqlParamList.AddRange(parameterArray);

            //m_DataBase.AddParameter(ref sqlParamList);

            //String SQLCommand = "SetMaxScheduleNum";

            //DataSet dataset = new DataSet();
            //dataset = m_DataBase.ExecuteStoredProcedureWithReturn(SQLCommand);

            #endregion
        }

Open in new window

Kyle AbrahamsSenior .Net DeveloperCommented:
Just a couple of notes:

no need to call this as you have a new command:
command.Parameters.Clear();


if you set these both to error
(EG:
 dataAdapter.MissingMappingAction = MissingMappingAction.Passthrough;
dataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

//becomes:
    adapter.MissingMappingAction = MissingMappingAction.Error
    adapter.MissingSchemaAction = MissingSchemaAction.Error 

Open in new window

)
does it make a difference?


Doing more research on this a suggested solution was to turn the connection pooling off in the connection string.  ("pooling=false" for ADO and "OLE DB Services=-4;" for OLE DB)

I haven't experienced this issue before so trying different things.

Also, if you call a datareader and do it that way do you have the same results?  (You can do it with a few columns and throw in a datatable just to test).
Vitor MontalvãoMSSQL Senior EngineerCommented:
This is a result from a stored procedure? If affirmative, what happens when you run the stored procedure for that week in particular and from SSMS directly?
axnst2Author Commented:
I was able to resolve the issue.  Still not sure of the root cause, but I had to make an adjustment to the procedure and as a result I formatted my output columns to all be varchars and now the issue is gone.  So I don't know if there was something odd with the datetimes and integers or what.  The C# code is used throughout my department and we all have stored procedures that return datetime and integer types and never had an issue.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
axnst2Author Commented:
doesn't define a root cause
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.