axnst2
asked on
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.
ASKER
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.TdsP arser.TryR un(RunBeha vior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlD ataReader. TryHasMore Results(Bo olean& moreResults)
at System.Data.SqlClient.SqlD ataReader. TryNextRes ult(Boolea n& more)
at System.Data.SqlClient.SqlD ataReader. NextResult ()
at System.Data.ProviderBase.D ataReaderC ontainer.N extResult( )
at System.Data.Common.DataAda pter.FillN extResult( DataReader Container dataReader)
at System.Data.Common.DataAda pter.FillF romReader( DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
at System.Data.Common.DataAda pter.Fill( DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataA dapter.Fil lInternal( DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataA dapter.Fil l(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataA dapter.Fil l(DataSet dataSet)
at PPG.AC.NA.SS.DBAccess.SQLD atabase.Ex ecuteStore dProcedure WithReturn (String SQLCommand) in c:\projects\ppg\PAC_Store_ Systems\Ne w Store System\PPG.AC.NA.SS.DBAcce ss\SQLData base.cs:li ne 301
Here is the stack trace if that helps.
at System.Data.SqlClient.TdsP
at System.Data.SqlClient.SqlD
at System.Data.SqlClient.SqlD
at System.Data.SqlClient.SqlD
at System.Data.ProviderBase.D
at System.Data.Common.DataAda
at System.Data.Common.DataAda
at System.Data.Common.DataAda
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at PPG.AC.NA.SS.DBAccess.SQLD
Can you post your code for the call? (you can hide actual connection strings)
ASKER
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
}
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:
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).
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
)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).
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
doesn't define a root cause
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:
Open in new window