SQL 服务器 MVC C# 的连接字符串



>我正在制作一个在线商店 MVC Web,我为类别制作了一个表格并用数据填充了它,并为产品制作了一个表格并填充了数据,现在如何连接到这些数据库以在网络上预览它们(注意:我想按 在网络上的商店 ,然后它会将我们带到类别,然后在按类别后,我们将拥有这些类别中的产品。 这是我的商店控制器:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCOnlineShop.Models;
namespace MVCOnlineShop.Controllers
{
public class StoreController : Controller
{
OnlineStoreEntities storeDB = new OnlineStoreEntities();
//
// GET: /Store/
public ActionResult Index()
{
var Categories = storeDB.Categories.ToList();
return View(Categories);
}
//
// GET: /Store/Browse
public ActionResult Browse(string Category)
{
// Retrieve Category and its Associated Products from database
var CategoryModel = storeDB.Categories.Include("Products")
.Single(g => g.Name == Category);
return View(CategoryModel);
}
//
// GET: /Store/Details
public ActionResult Details(int id)
{
var Product = storeDB.Products.Find(id);
return View(Product);
}
//
// GET: /Store/Browse?Category=Games
}
} 

你能给我正确的SQL服务器连接字符串形式吗

在 OnlineStoreEntities类上按 f12,然后检查 OnlineStoreEntities :base("connectionstringName") 中提到的 connectionString 。 检查 Web 配置中的连接字符串名称。 在 Web 配置中,可以更改连接字符串值。

https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/database-first-development/creating-the-web-application

通过本教程了解数据库优先方法。

最新更新