初始SQL数据库连接速度极慢

时间:2017-07-11 20:04:19

标签: angularjs asp.net-mvc

我开发了一个asp.net mvc / angular网站,它在我的本地机器上工作正常,但是当上传到我的GoDaddy共享主机帐户时,当用户首次尝试登录时,需要FOREVER创建初始数据库连接网站&我不知道如何解决(我知道我总是可以转移到更好的主机上,但是我想看看是否有任何我可以先尝试的编码解决方案&它&#39 ;我的代码中没有遗漏问题。)

这是我的网站:whesearchreporting.com

尝试使用任意随机登录&登录您会注意到接收"无效登录"大约需要15-20秒。消息(注意:这只会影响第一个人访问网站。一旦用户尝试连接,任何尝试访问该网站的添加用户都可以立即登录)。

到目前为止我的观察结果:

  • 这仅影响初始登录(即初始数据库连接)。一旦你进入,你可以点击网站上的任何内容,甚至退出&重新登录没有问题。

  • 如果我登录计算机A(需要一些时间),我几乎可以立即以不同的用户身份登录计算机B.

  • 我读过GoDaddy超载他们的共享托管服务器,所以我认为这是罪魁祸首,但不是正面的。

这是我的一些代码:

角度代码:

 angular.module('dashboardApp', [])
.controller('loginController', function ($scope, $location, $window, LoginService) {
    $scope.IsLoggedIn = false;
    $scope.Message = '';
    $scope.Submitted = false;
    $scope.IsFormValid = false;

    $scope.AccountData = {
        Email: '',
        Password: ''
    };

    //Check is the form valid or not. 
    $scope.$watch('frmLogin.$valid', function (newVal) {            
        $scope.IsFormValid = newVal;
    });

    $scope.Login = function () {
        $scope.loading = true;
        $scope.Submitted = true;
        if ($scope.IsFormValid) {
            LoginService.GetUser($scope.AccountData).then(function (d) {
                if (d.data.Email != null) {
                    $scope.IsLoggedIn = true;
                    $window.location.href = "/Account/Dashboard";
                }
                else {
                    $scope.Message = "Invalid login";
                    $scope.loading = false;
                }
            });
        }
    };
})

.factory('LoginService', function($http) {
    var fac = {};
    fac.GetUser = function (d) {
        return $http({
            url: '/Home/UserLogin',
            method: 'POST',
            data: JSON.stringify(d),
            headers: { 'content-type': 'application/json' }
        });
    };
    return fac;
 });

我的HomeController

public JsonResult UserLogin(Account account)
    {
        _accountService = new AccountService();
        if (_accountService.Login(account) != null)
        {
            //valid login credentials.  Set cookie & return client data
            FormsAuthentication.SetAuthCookie(account.Email, false);
        }
        else
        {
            //invalid login.  Delete client data
            account = null;
        }
        return Json(account);
    }

我的AccountRepositoryLogin方法):

public string Login(Account a)
    {
        Account account = _accountRepository.GetAccountByEmail(a.Email);
        a.Password = a.Password.Encrypt(a.Email);

        if (account != null)
        {
            //password matches
            if(account.Password == a.Password)
            {
                return account.Email;
            }
            else
            {
                return null;
            }
        }

        return null;             
    }

最后,我的数据库连接抓取了帐户信息:

 private readonly Connection _conn;

 public Account GetAccountByEmail(string email)
 {
        Account account;

        using (MySiteEntities db = _conn.GetContext())
        {
            account = (from c in db.Accounts
                      where c.Email.Equals(email)
                      select c).FirstOrDefault();
        }

        return account;
}

任何想法为什么这个初始连接如此缓慢&我有什么想法可以改善表现?

由于

1 个答案:

答案 0 :(得分:1)

你知道GoDaddy是否正在使用Windows Server吗?因为这听起来像是IIS的一个问题,所以它会陷入休眠状态"在一段时间没有使用之后的状态。您可以更改此设置,但据我所知,您无法将其关闭。

相关问题