Advertisement
RaWRCoder

MySQL + ASP .NET

Dec 7th, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using System.Web.Mvc;
  4. using System.Web.Routing;
  5. using System.Xml;
  6. using Legend3_Shared.MySQL;
  7. using MySql.Data.MySqlClient;
  8.  
  9. namespace VoxelPro_WebSite
  10. {
  11.     public class MvcApplication : System.Web.HttpApplication
  12.     {
  13.         public static MySqlConnection Connection = new MySqlConnection("YOUR_CONNECTION_STRING");
  14.         protected void Application_Start()
  15.         {
  16.         if (Connection.State == ConnectionState.Closed)
  17.                 Connection.Open();
  18.             Connection.Query("select Value from counters where name='Visits'", r =>
  19.             {
  20.                 var result = r["Value"];
  21.                 Application["Visits"] = (long) result;
  22.                 return false;
  23.             });
  24.             AreaRegistration.RegisterAllAreas();
  25.             RouteConfig.RegisterRoutes(RouteTable.Routes);
  26.             Connection.Close();
  27.         }
  28.  
  29.         private void Session_Start(object sender, EventArgs e)
  30.         {
  31.             if (Connection.State == ConnectionState.Closed)
  32.                 Connection.Open();
  33.             Connection.NonQuery($"update counters set Value={visits+1} where name='Vists'");
  34.             Connection.Close();
  35.         }
  36.  
  37.         private void Session_End(object sender, EventArgs e)
  38.         {
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement