Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

deployment - ASP.NET Core Web App not working after deploying on IIS or Linux Server

I have created a ASP.NET Core MVC web app. It has simple crud operations and does not involve Entity Framework. It runs fine when I run it from VS2019. But when I deploy the published application on Linux or Windows, it throws error. I am unable to catch the error but I have figured out that the error is caused by a function which fetch records from database.

What might be causing this abnormality.

Also is there a way to debug the application after deployment.

Here is the piece of code causing issues.

 public List<Admin> GetAllRecords()
        {
            List<Admin> list = new List<Admin>();

            using (MySqlConnection conn = new MySqlConnection("Connection string goes here"))
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand("select * from table", conn);

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        list.Add(new Admin()
                        {
                            Col1= Convert.ToInt32(reader["Col1"]),
                            Col2= reader["Col2"].ToString(),
                            Col3= reader["Col3"].ToString(),
                            Col4= reader["Col4"].ToString(),
                            Col5= reader["Col5"].ToString(),
                            Col6= reader["Col6"].ToString(),
                            Col7= reader["Col7"].ToString(),
                            Col8= DateTime.ParseExact(reader["Col8"].ToString(), "M/d/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd"),
                            Col9= DateTime.ParseExact(reader["Col9"].ToString(), "M/d/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd"),
                            Col10= reader["Col10"].ToString(),
                            Col11= reader["Col11"].ToString(),
                            Col12= reader["Col12"].ToString(),
                            Col13= Convert.ToInt32(reader["Col13"])
                        });
                    }
                }
                conn.Close();
            }
            return list;
        }

I use this in the controller as

AdminDataContext adminDataContext = new AdminDataContext();
List<Admin> records = new List<Admin>();
records = adminDataContext.GetAllRecords();
return View(records);

I am willing to provide more info and sorry if the question is not detailed.


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

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...