Cla*_*ear 3 sql linq sql-server asp.net
我正在制作一个.net系统.我正在使用LINQ和MVC.我不得不创建实时数据库,并希望这可以顺利运行,但事实并非如此.
新的SQL SERVER - 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."
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索了这个错误,发现人们认为它与"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;
}
}
Run Code Online (Sandbox Code Playgroud)
*请注意这在使用开发服务器时确实有效.Microsoft Windows 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);
}
Run Code Online (Sandbox Code Playgroud)
服务
readonly Repository _repository = new Repository();
public bool AddAccess(Access access)
{
return _repository.AddAccess(access);
}
Run Code Online (Sandbox Code Playgroud)
真的不知道我错过了什么.
在此先感谢您的帮助.
克莱尔:-)
你知道为什么要触发分布式事务吗?这是您需要调查的内容.通常的罪魁祸首是来自单个TransactionScope的多个ADO.Net连接.请参阅ADO.NET和System.Transactions以及ADO.NET和LINQ to SQL.确保在事务范围中使用单个连接(即LINQ2SQL上下文).无论如何,您不必每个HTTP呼叫使用多个.
| 归档时间: |
|
| 查看次数: |
252 次 |
| 最近记录: |