There is an error while running my code:
local host says undefined:
an exception is occure :
An exception of type 'System.NullReferenceException' occurred in WebApplication13.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object.
web config file:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="dbcs" connectionString="data source=DESKTOP-9OM984O;initial catalog=Airbluedb;integrated security=true"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
C# CODE
namespace WebApplication13
{
public partial class WebForm1 : System.Web.UI.Page
{
[WebMethod]
public static List<object> GetChartData()
{
string query = "SELECT [time],[average] FROM [dbo].[graph] WHERE ipaddress='192.168.15.167'";
string constr = ConfigurationManager.ConnectionStrings["dbsc"].ConnectionString;
List<object> chartData = new List<object>();
chartData.Add(new object[]
{
"time", "average"
});
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
chartData.Add(new object[]
{
sdr["time"], sdr["average"]
});
}
}
con.Close();
return chartData;
}
}
}
}
}
please help me as i am stucking with this error.
i dont know whats wrong with this code or why its not giving input