我正在制作一个.net系统。我正在使用 LINQ 和 MVC。我必须创建实时数据库,并希望它能够顺利运行,但事实并非如此。
新 SQL 服务器 - Microsoft Windows NT 5.0 (2195) / 8.00.760
我创建了一个可以添加/编辑/删除的管理员用户。基本上,如果我尝试添加(.InsertOnSubmit
)或删除(.DeleteOnSubmit
)任何行,但在我编辑时不会收到以下错误。
"Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool."
我用谷歌搜索了这个错误,发现人们认为它与“MSDTC 服务”有关,但这似乎是在服务上打勾的。我已经通过 SQL Server Management 登录到数据库,这个用户可以添加/删除。
一个例子:
Controller
if (_service.AddAccess(access)) return RedirectToAction("Access");
public Repository()
{
_db = new DataClassDataContext(ConfigurationManager.ConnectionStrings["RegistrarsServices"].ConnectionString);
}
public void Save()
{
_db.SubmitChanges();
}
public bool AddAccess(Access access)
{
try
{
using (var scope = new TransactionScope())
{
_db.Accesses.InsertOnSubmit(access);
Save();
scope.Complete();
}
return true;
}
catch (Exception)
{
return false;
}
}
*请注意,这在使用开发服务器时确实有效。微软视窗 NT 5.2 (3790) / 10.0.1600.22
控制器
private readonly ServiceAdministration _service = new ServiceAdministration();
public ActionResult AddAccess()
{
return View(new EmailViewModel());
}
[HttpPost]
public ActionResult AddAccess(EmailViewModel emailViewModel)
{
if (emailViewModel.Button == "Back") return RedirectToAction("Access");
if (!ModelState.IsValid) return View(emailViewModel);
Access access = new Access();
access.emailAddress = emailViewModel.emailAddress;
if (_service.AddAccess(access)) return RedirectToAction("Access");
emailViewModel.errorMessage = "An error has occurred whilst trying to grant access. Please try again later.";
return View(emailViewModel);
}
服务
readonly Repository _repository = new Repository();
public bool AddAccess(Access access)
{
return _repository.AddAccess(access);
}
真的不知道我错过了什么。
提前感谢您的帮助。
克莱尔:-)