Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 views
in Technique[技术] by (71.8m points)

asp.net core - Sybase ASE (+ Dapper+.NetCore) Exception:A request to send or receive data was disallowed because the socket is not connected ... no address

I'm calling sybase ase via Dapper with parameterized sql in .NetCore 2.

I keep getting the "A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied." error

but the error seems to mean "something went wrong" Its been bad data ypes on return object, connection timeouts etc.

I'm spending a ton of time trying to brute force debug these errors. Is there a better way to debug these to get to the root issue?

example working code:

var aseSqlConnectionString = Configuration.GetConnectionString("SybaseDBDapper");
            
            StringBuilder query = new StringBuilder();

            query.Append("SELECT stud_id, ad_guid, ad_name, ad_pass_expire_dt, ad_last_login_dt, alumni");
            query.Append("      from student  ");
            query.Append("  where LOWER( ad_name ) = Lower( @studentAdName )   ");

            string sql = query.ToString();

            DapperTools.DapperCustomMapping< StudentAdDataResponse >( );

            try
            {
                using ( IDbConnection db = new AseConnection(aseSqlConnectionString) )
                {
                    var arguments = new
                                        {
                                            studentAdName = sAdName,
                                        };

                    List< StudentAdDataResponse > ll = new List< StudentAdDataResponse >();
                    //StudentAdDataResponse res =  db.QueryFirst<StudentAdDataResponse>(sql, arguments);
                    //ll.Add( res );

                    ll = db.Query<StudentAdDataResponse>(sql, arguments).ToList();
                    return ll;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine( ex.ToString(  ) );
                return null;
            }

example bad code

string sql        = " SELECT period.period_day_cd,    " +
                                "           period.period_no,    " +
                                "           period.period_start_tm,    " +
                                "           period.period_end_tm,    " +
                                "           classroom.clsrm_loc_cd,    " +
                                "           classroom.clsrm_no,    " +
                                "           course.course_name,    " +
                                "           student_schedule.stud_sched_eff_dt,    " +
                                "           student_schedule.sched_type_cd,    " +
                                "           code.code_desc,    " +
                                "           staff.staff_lname,    " +
                                "           staff.staff_fname,    " +
                                "           staff.staff_mi, " +
                                "           'N' as first_eff_dt" +
                                "      FROM code,    " +
                                "           classroom,    " +
                                "           course,    " +
                                "           period,    " +
                                "           staff,    " +
                                "           student_schedule,    " +
                                "           class,    " +
                                "           class_period,    " +
                                "           schedule_item,    " +
                                "           stud_class_sched   " +
                                "     WHERE ( student_schedule.sched_type_cd  = code.code_id ) and   " +
                                "           ( class.clsrm_id = classroom.clsrm_id ) and   " +
                                "           ( schedule_item.sched_item_id = course.sched_item_id ) and   " +
                                "           ( student_schedule.stud_sched_id = stud_class_sched.stud_sched_id ) and   " +
                                "           ( class_period.cls_period_id = stud_class_sched.cls_period_id ) and   " +
                                "           ( class_period.period_id = period.period_id ) and   " +
                                "           ( class_period.cls_id = class.cls_id ) and   " +
                                "           ( class.staff_id = staff.staff_id ) and   " +
                                "           ( class.sched_item_id = schedule_item.sched_item_id ) and   " +
                                "           ( student_schedule.enrtype_id = @enrtypeid ) " +
                                "           order by student_schedule.stud_sched_eff_dt desc,   " +
                                "                   code.code_desc,   " +
                                "                   period.period_day_cd, " +
                                "                   period.period_start_tm  ";


            var aseSqlConnectionString = configuration.GetConnectionString("SybaseDBDapper");
            dapperTools.DapperCustomMapping<StdInfoScheduleCV>();

            try
            {
                List<StdInfoScheduleCV> ll = new List<StdInfoScheduleCV>();

                using ( IDbConnection db = new AseConnection( aseSqlConnectionString ) )
                {
                    try
                    {
                        db.Open(    );


                        var arguments = new
                                            {
                                                enrtypeid = EnrTypeId,
                                            };

                        ll = jcdcDbQuery< StdInfoScheduleCV >( db, sql, arguments );
                    }
                    catch ( Exception ex )
                    {
                        throw;
                    }
                    finally
                    {
                        db.Close();
                    }

                    return ll;
                }
            }
            catch ( Exception ex )
            {
                Trace.WriteLine(ex.ToString());
                //return new List< StdInfoScheduleCV >();
                throw;
            }

I've tried everything I can think of, but can't find the issue.

What steps can I take to diagnose the Sybase ASE + Dapper issue.

The non working code was ported over from a working asp.net mvc 4.5 app, and the db code converted to dapper and .netcore


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

After digging into dapper for a while, I remembered that back in the day working on the .Net library that sat on top of the Sybase driver, we'd had issues with int64s because internally in Sybase ints' weren't stored that way., that we had to solve in our libraries.

In my query objects (in and out) I changed all the int64s to int32s, and Sybase was was happy and the error went away.

Sorry there is not a more concrete way to diagnose the issue.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...