When would SqlCommand.ExecuteReader() return null?

后端 未结 5 853
孤城傲影
孤城傲影 2020-12-11 15:52

When using calling the SqlCommand.ExecuteReader() method, ReSharper tells me I have a possible NullReference exception when I use the SqlDataReader object after

5条回答
  •  我在风中等你
    2020-12-11 16:27

    I have determined one reason why ExecuteReader() can return null.

    In the case where I was getting a null, I had sent my client a script to update a stored procedure. My client's Sql Server (2000) is set up so that DB users need a permission to execute a stored procedure. When they updated the SP the permission was removed and not re-assigned. In this instance the SqlCommand.ExecuteReader() returned a null.

    Re-assigning the permission fixed this.

提交回复
热议问题