locked
Problem to exceptioin RRS feed

  • Question

  • User364663285 posted

    Hi,
    What can be reason of

       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
    

    due to line

                            sqlAd.Fill(sqlDt);
    

    to the codes below.

                List<HouseData> houseList = new List<HouseData>();
                try
                {
                    using (SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["Mssqlconn3"].ConnectionString))
                    {
                        using (SqlCommand sqlCmd = new SqlCommand("SELECT cast(ROW_NUMBER() OVER (ORDER BY house_id ASC) as int) serial_id, house_id, rent_type, house_name, area, area_unit2, clicked_times, area_unit, area_size, isnull(construct_area_size,0) construct_area_size, isnull(request_times,0) request_times, release_period_from, CONVERT(varchar,register_date,105) register_date,CONVERT(varchar,upd_date,105) upd_date, address1, address2, price, price_curr, ltrim(rtrim(cast(raised_by_user_id as varchar(50)))) raised_by_user_id FROM house_tab where isnull(raised_by_user_id,0)=@raiser and isnull(deleted,'')<>'Y'", sqlConn))
                        {
                            sqlConn.Open();
                            sqlCmd.CommandType = CommandType.Text;
    
                            sqlCmd.Parameters.AddWithValue("@raiser", System.Web.HttpContext.Current.Session["user_id"]);
                            SqlDataAdapter sqlAd = new SqlDataAdapter(sqlCmd);
                            DataTable sqlDt = new DataTable();
    
                            sqlAd.Fill(sqlDt);
                            sqlConn.Close();
                            if (null != sqlDt)
                            {
                                houseList = sqlDt
                                                .AsEnumerable()
                                                .Select(dataRow => new HouseData
                                                {
                                                    serial_id = dataRow.Field<int>("serial_id"),
                                                    house_id = dataRow.Field<int>("house_id"),
                                                    house_name = dataRow.Field<string>("house_name"),
                                                    address1 = dataRow.Field<string>("address1"),
                                                    address2 = dataRow.Field<string>("address2"),
                                                    area = dataRow.Field<string>("area"),
                                                    area_unit = dataRow.Field<string>("area_unit"),
                                                    rent_type = dataRow.Field<string>("rent_type"),
                                                    register_date = dataRow.Field<string>("register_date"),
                                                    upd_date = dataRow.Field<string>("upd_date"),
                                                    area_unit2 = dataRow.Field<string>("area_unit2"),
                                                    clicked_times = dataRow.Field<decimal>("clicked_times"),
                                                    construct_area_size = dataRow.Field<decimal>("construct_area_size"),
                                                    request_times = dataRow.Field<decimal>("request_times"),
                                                    area_size = dataRow.Field<decimal>("area_size"),
                                                    price = dataRow.Field<decimal>("price"),
                                                    price_curr = dataRow.Field<string>("price_curr"),
                                                    raised_by_user_id = dataRow.Field<string>("raised_by_user_id"),
                                                })
                                                .ToList();
                            }
                        }
                    }
                }

    Wednesday, September 12, 2018 9:37 AM

All replies

  • User753101303 posted

    And which exception it is ? A full message looks like for example :

    System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
       at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling)
       at etc..
    

    Wednesday, September 12, 2018 11:39 AM
  • User364663285 posted

    Dear,
    Both projects are having the same details of connections. Why can't the 1st URL (for 1st project) show the list, while the 2nd URL is having no issue?

    http://www.SearchHouseLive.com/HouseList4/Default.aspx?userid=mc1

    http://www.SearchHouseLive.com/HouseList4B/Default.aspx?userid=mc1

    Thursday, September 13, 2018 6:52 AM
  • User753101303 posted

    It could be a different application pool configuration for example... Anyway rather than trying to guess you should start from the exception message that should give also an exception type and an error message that should help to better make sure about what happens.

    If missing check that you are logging ex.ToString() to get full details rather than just the call stack...

    Thursday, September 13, 2018 7:49 AM
  • User364663285 posted

    Yes, I only get

       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
    

    from StackTrace. How can you know the problem is with the connection?

    Thursday, September 13, 2018 8:07 AM
  • User753101303 posted

    The stack trace is useful but just tell where it happens (not what happened). I assume this is your own exception logging code ? Use exception.ToString(); to get full details. As show earlier before the stack trace you have an exception type and an error message (as well as inner exceptions).

    Unless by chance you ran into the more likely cause (maybe here SQL Server integrated security with a wrong pool identity) it is much quicker to start from the actual exception message.

    Thursday, September 13, 2018 8:43 AM
  • User364663285 posted

    Sorry to that, I am getting the current Exception message in above, by this - ex2.StackTrace.ToString(), while ex2 is defined as Exception.

    Thursday, September 13, 2018 8:49 AM
  • User753101303 posted

    Ok so please change ex2.StackTrace.ToString() to just ex2.ToString() so that we can ge the neede details.

    Thursday, September 13, 2018 11:10 AM
  • User364663285 posted

    Here is exception I've got

       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
       at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
       at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
       at System.Data.SqlClient.SqlDataReader.get_MetaData()
       at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
       at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
       at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
       at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
       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(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
    

    Friday, September 14, 2018 3:01 AM
  • User753101303 posted

    Not sure what I can add. This is still just a stack trace. For example :

    using System;
    
    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int i=0;
                try
                {
                    i = i / i;
                }
                catch(Exception ex)
                {
                    Console.WriteLine(ex.StackTrace.ToString());
                    Console.WriteLine(ex.ToString());
                }
            }
        }
    }
    

    The first WriteLine shows :

       at ConsoleApp1.Program.Main(String[] args)

    The second line shows :

    System.DivideByZeroException: Attempted to divide by zero.
       at ConsoleApp1.Program.Main(String[] args)

    You have 5000+ posts but never noticed that yet ?

    Friday, September 14, 2018 7:05 AM