按照 Asp.net MVC 教程无法连接到 SQL Express 的实例
Unable to connect to instance of SQL Express following Asp.net MVC tutorial
我在尝试从使用 LocalDb 切换到使用 Microsoft SQL Server 中的 SQL express 实例时遇到问题。以下是我的连接字符串:
<connectionStrings>
<add name="DefaultConnection"
connectionString="Server=.\MSSQLSERVER; Database=MvcDemo; Trusted_Connection=true; multipleActiveResultSets=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>
连同错误信息:Error Message on SQL Management Studio. Here is the picture of the Service name: SQL Server Instance。
试试这个,
我假设您的 dbcontext class 名称是“ApplicationDbContext”。
<connectionStrings>
<add name="ApplicationDbContext"
connectionString="Data Source=.\MSSQLSERVER; Initial Catalog=MvcDemo; Trusted_Connection=true; multipleActiveResultSets=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>
您还可以让服务器资源管理器 window 为您提供正在查看的数据库的连接字符串,方法是右键单击数据库节点,然后单击修改连接。单击“高级”,连接字符串值将显示在“数据源”值下。
您似乎没有授予 Windows 帐户访问数据库的权限。在 SMMS 中,向下转到以黄色突出显示的菜单项。右键单击登录,select“新登录”并填写表格,selecting windows 身份验证。
然后去数据库,MvcDemo/Security/Users(红色箭头所示)。右键单击并添加“新用户”。 Select 下拉列表中的“Windows 用户”和 select 你自己。
我能够通过将服务器名称更改为我笔记本电脑的名称来进行连接,connectionString 中的其他所有内容都保持不变。如果在 windows 上,请转到 windows 开始菜单 -> 查看您的电脑名称。在其他教程中,我看到人们也通过检查服务下 SQL 服务器实例的名称来使用服务器实例名称。
<connectionStrings>
<add name="ApplicationDbContext"
connectionString="Server=Name_Of_PC; Initial Catalog=MvcDemo; Trusted_Connection=true; multipleActiveResultSets=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>
我在尝试从使用 LocalDb 切换到使用 Microsoft SQL Server 中的 SQL express 实例时遇到问题。以下是我的连接字符串:
<connectionStrings>
<add name="DefaultConnection"
connectionString="Server=.\MSSQLSERVER; Database=MvcDemo; Trusted_Connection=true; multipleActiveResultSets=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>
连同错误信息:Error Message on SQL Management Studio. Here is the picture of the Service name: SQL Server Instance。
试试这个, 我假设您的 dbcontext class 名称是“ApplicationDbContext”。
<connectionStrings>
<add name="ApplicationDbContext"
connectionString="Data Source=.\MSSQLSERVER; Initial Catalog=MvcDemo; Trusted_Connection=true; multipleActiveResultSets=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>
您还可以让服务器资源管理器 window 为您提供正在查看的数据库的连接字符串,方法是右键单击数据库节点,然后单击修改连接。单击“高级”,连接字符串值将显示在“数据源”值下。
您似乎没有授予 Windows 帐户访问数据库的权限。在 SMMS 中,向下转到以黄色突出显示的菜单项。右键单击登录,select“新登录”并填写表格,selecting windows 身份验证。
然后去数据库,MvcDemo/Security/Users(红色箭头所示)。右键单击并添加“新用户”。 Select 下拉列表中的“Windows 用户”和 select 你自己。
我能够通过将服务器名称更改为我笔记本电脑的名称来进行连接,connectionString 中的其他所有内容都保持不变。如果在 windows 上,请转到 windows 开始菜单 -> 查看您的电脑名称。在其他教程中,我看到人们也通过检查服务下 SQL 服务器实例的名称来使用服务器实例名称。
<connectionStrings>
<add name="ApplicationDbContext"
connectionString="Server=Name_Of_PC; Initial Catalog=MvcDemo; Trusted_Connection=true; multipleActiveResultSets=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>