localhost无法连接到db,而部署的代码可以

时间:2018-03-24 01:44:28

标签: c# .net visual-studio entity-framework

我使用Arvixe作为我的网络主机,并创建了一个带有个人用户帐户的.NET 4.5 MVC应用程序。我创建了一个名为“SecurityModel”的ADO.NET实体数据模型数据库,将我的ApplicationDbContext更新为“joerdie_securityEntities”,并将我的连接字符串切换为以下内容:

   <add name="joerdie_securityEntities" connectionString="Data Source=localhost;Initial Catalog=joerdie_security;Integrated Security=false;User ID=myID;Password=myPassword" providerName="System.Data.SqlClient" />

我这样做是因为我可以使用我自己的也使用Arvixe托管的SQL服务器数据库。当我部署这个基本应用程序时,我能够创建一个没有问题的新用户,并且新用户被输入SQL服务器数据库。但是,当我尝试在localhost中创建新用户时,在声明“result”期间,用户创建在以下方法中失败。

    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> Register(RegisterViewModel model)
    {
        if (ModelState.IsValid)
        {
            var user = new ApplicationUser { UserName = model.Email, Email = model.Email };

            try
            {
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);

        }

            catch (Exception e) { 
                Console.WriteLine(e.Message);
            }


    }

        // If we got this far, something failed, redisplay form
        return View(model);
    }

异常被捕获但是为空,我从未进入以下if语句。我能够将其他模型引入这个确切的SQL Server实例,并且它们更新得很好。如何将其设置为能够在指向我的SQL Server实例的localhost上进行调试?

编辑:添加控制台输出。

Exception thrown: 'System.Data.SqlClient.SqlException' in mscorlib.dll
Application Insights Telemetry (unconfigured): {"name":"Microsoft.ApplicationInsights.Dev.Request","time":"2018-03-24T02:31:06.2230673Z","tags":{"ai.operation.name":"POST Account/Register","ai.operation.id":"MJK7rNb0X7k=","ai.location.ip":"::1","ai.cloud.roleInstance":"joerdie-Desktop","ai.internal.sdkVersion":"web:2.2.0-738"},"data":{"baseType":"RequestData","baseData":{"ver":2,"id":"MJK7rNb0X7k=","name":"POST Account/Register","duration":"00:01:01.1920000","success":true,"responseCode":"200","url":"http://localhost:53015/Account/Register","properties":{"DeveloperMode":"true"}}}}
The thread 0x10ec has exited with code 0 (0x0).

0 个答案:

没有答案