我已安裝Visual Studio 2015.我正在Visual C#中創建新的Web窗體項目。由於所有的功能,如註冊和登錄存在,但它不起作用在我的情況。我還評論上面錯誤生成的行。當我嘗試註冊用戶時,我在代碼中出現錯誤。Visual Studio 2015問題。 mscorlib.dll中發生'System.Data.SqlClient.SqlException',但未在用戶代碼中處理
下面錯誤產生
An exception of type 'System.Data.SqlClient.SqlException' occurred in mscorlib.dll but was not handled in user code
Additional information: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)
代碼如下。
using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Owin;
using WebApplication1.Models;
namespace WebApplication1.Account
{
public partial class Register : Page
{
protected void CreateUser_Click(object sender, EventArgs e)
{
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var signInManager = Context.GetOwinContext().Get<ApplicationSignInManager>();
var user= new ApplicationUser() { UserName = Email.Text, Email = Email.Text };
//error is generated in below line
IdentityResult result = manager.Create(user, Password.Text);
if (result.Succeeded)
{
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
//string code = manager.GenerateEmailConfirmationToken(user.Id);
//string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
//manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>.");
signInManager.SignIn(user, isPersistent: false, rememberBrowser: false);
IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
else
{
ErrorMessage.Text = result.Errors.FirstOrDefault();
}
}
}
}
那麼這個錯誤消息似乎很明顯:「無法找到本地數據庫運行時安裝。確認SQL Server Express已正確安裝,並且啓用了本地數據庫運行時功能。 –
檢查連接字符串。 –