无法在 fiddler 上显示记录

unable to show a record on fiddler

我使用 ASP.net 和 C# 连接到外部 SQL Server 2012 创建了一个网站 api。我的连接字符串是 myConnection.ConnectionString = "Data Source=./PALLAVI-PC/SQLEXPRESS;Initial Catalog=StudentDB;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework";

代码似乎没有错误。但是当我部署该服务并尝试在 fiddler 上提取记录时,出现 404 错误。 GET url 是 localhost:xxxxx/api/student/1

正在发布以下代码:

StudentController.cs

   //api/student/id
    [HttpGet]
     [ActionName("GetStudentByID")]
    public Student Get(int id)
    {
        //SQL Reader
        SqlDataReader reader = null;

        //SQL Connection class
        SqlConnection myConnection = new SqlConnection();

        //creating the connection string            
        myConnection.ConnectionString = "Data Source=./PALLAVI-PC/SQLEXPRESS;Initial Catalog=StudentDB;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework";

        //SQL Commands class
        SqlCommand sqlCmd = new SqlCommand();
        sqlCmd.CommandType = System.Data.CommandType.Text;

        //sql query
        sqlCmd.CommandText = "Select * from Students where Roll_Number=" + id + ";";

        sqlCmd.Connection = myConnection;

        //opening the connection
        myConnection.Open();

        //extracting the record
        reader = sqlCmd.ExecuteReader();

        //object of class student
        Student myStudent = null;

        while (reader.Read())
        {
            myStudent = new Student();
            myStudent.Roll_Number = Convert.ToInt32(reader.GetValue(0));
            myStudent.FirstName = reader.GetValue(1).ToString();
            myStudent.LastName = reader.GetValue(2).ToString();
            myStudent.Class = Convert.ToInt32(reader.GetValue(3));
            myStudent.Gender = reader.GetValue(4).ToString();
        }

        return myStudent;

        //close connection
        myConnection.Close();


    }

如果我将连接字符串中的斜杠改为转发,我会收到错误 unrecognized character

将您的连接字符串更改为 myConnection.ConnectionString = @"Data Source=PALLAVI-PC\SQLEXPRESS;Initial Catalog=StudentDB;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework";