Вот конфиг MVC
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using WebApplication.Models;
namespace WebApplication
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
Database.SetInitializer(new StaticDbInitializer());
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
}
При запуске первым должен сработать класс:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.IO;
using XO;
using Newtonsoft.Json;
using System.Data.SqlClient;
using System.Data;
namespace WebApplication.Models
{
public class StaticDbInitializer
{
public void StatisticDB()
{
string jsonData = @"C:\Users\EvgenieL\Source\Repos\XO\XO\XO\bin\Debug\stats.json";
List<Statistcs> m = JsonConvert.DeserializeObject<List<Statistcs>>(jsonData);
}
public static bool AddStatistics(Statistcs m)
{
var conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\EvgenieL\Source\Repos\XO\XO\WebApplication\App_Data\XO.mdf;Integrated Security=True");
var command = new SqlCommand();
command.Connection = conn;
command.CommandType = CommandType.Text;
command.CommandText = $"INSERT INTO Statistic(Date, Result, StepCounter, UserFirst) VALUES('{m.Date}', '{m.Result}', {m.StepCounter}, '{m.UserFirst}')";
try
{
conn.Open();
command.ExecuteNonQuery();
}
catch
{
return false;
}
finally
{
conn.Close();
}
return true;
}
}
}
Подскажите в чем ошибка может быть и как исправить вот что выдает?