나는 ext.net 저장소를 채우기 위해 C# 함수를 작성했습니다. 한 응용 프로그램에서 제대로 작동하지만 동일한 코드가 다른 응용 프로그램에서 작동하지 않습니다. 나는 라인 26 라인 26이에 System.NullReferenceException
입니다 점점 오전 :SQL System.NullReferenceException
protected void fillStore(Ext.Net.Store store, string query)
{
SqlDataReader MyReader;
SqlConnection MyConnection = new SqlConnection();
MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
SqlCommand fillCommand = new SqlCommand();
fillCommand.CommandText = "select id, name from b2b_group";
fillCommand.CommandType = CommandType.Text;
fillCommand.Connection = MyConnection;
fillCommand.Connection.Open();
MyReader = fillCommand.ExecuteReader(CommandBehavior.CloseConnection);
store.DataSource = MyReader;
store.DataBind();
fillCommand.Dispose();
MyConnection.Dispose();
}
, 나는 하드로 통과 될 쿼리 문자열을 대체
여기MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
는 내 C# 기능입니다 - "select id, name from b2b_group"
중 하나를 코드화했습니다.
다른 프로젝트에서 동일한 코드를 사용하는 이유는 무엇입니까? nullReferenceException
을주는 이유를 알 수 없습니다.
내가 감독하고있는 작은 것이 있다는 것을 알고 있습니다. 누구든지 알아볼 수 있습니까?
정말 고마워요!
확실히 연결 문자열을 찾을 수 없습니다. 디버거에서 이것을 확인 했습니까? MyConnection.ConnectionString의 값을 표시합니다. XML 정의 방법을 보여줍니다. –
글쎄 그것은'ConnectionStrings [ "MyConnectionString"]'이 아마도 null 일 것 같다. 이 새 프로젝트의 구성에 추가 했습니까? – pquest
그게 다야! 나는 연결 문자열을 잊어 버렸어 .- 나는 어리석은 실수를 한 것을 알았다. ... – starvator