能够连接到 SQLEXPRESS2014,但从 Visual Studio 收到无效的对象名称错误
Able to connect to SQLEXPRESS2014, but getting Invalid object name error from Visual Studio
我正在尝试从 Visual Studio webforms 应用程序连接到 SQLEXPRESS2014。
看起来正在建立连接,但我正在
对象名称无效 'HumanResources.Employee'。
System.Data.SqlClient.SqlException: 对象名称无效 'HumanResources.Employee'.
当我在 Management Studio 中查询数据库时,它 returns 结果。
我正在使用 AdventureWorks2012 数据库。
我使用此数据源绑定到 Gridview。
aspx 页面
<asp:sqldatasource id="CustomersSource"
selectcommand="Select [BusinessEntityID], [NationalIDNumber], [LoginID]
From [HumanResources.Employee]"
connectionstring="<%$ ConnectionStrings:AdvWorksConnection%>"
runat="server"/>
连接字符串
<connectionStrings>
<add name="AdvWorksConnection" connectionString="data source=localhost\SQLEXPRESS2014;
initial catalog=AdventureWorks2012;persist security info=True;
Integrated Security=True;"
providerName="System.Data.SqlClient" />
</connectionStrings>
你能告诉我哪里做错了吗?连接字符串有问题吗
我相信你想要这个:
<asp:sqldatasource id="CustomersSource"
selectcommand="Select [BusinessEntityID], [NationalIDNumber], [LoginID]
From [AdventureWorks2012].[HumanResources].[Employee]"
connectionstring="<%$ ConnectionStrings:AdvWorksConnection%>"
runat="server"/>
然而,AdventureWorks2012
是数据库,HumanResources
是架构,Employee
是 table。
注意:您可以删除 [AdventureWorks2012].
并且查询仍应执行,因为您的连接字符串明确表示要使用 AdventureWorks2012
数据库。
我正在尝试从 Visual Studio webforms 应用程序连接到 SQLEXPRESS2014。 看起来正在建立连接,但我正在 对象名称无效 'HumanResources.Employee'。
System.Data.SqlClient.SqlException: 对象名称无效 'HumanResources.Employee'.
当我在 Management Studio 中查询数据库时,它 returns 结果。
我正在使用 AdventureWorks2012 数据库。 我使用此数据源绑定到 Gridview。
aspx 页面
<asp:sqldatasource id="CustomersSource"
selectcommand="Select [BusinessEntityID], [NationalIDNumber], [LoginID]
From [HumanResources.Employee]"
connectionstring="<%$ ConnectionStrings:AdvWorksConnection%>"
runat="server"/>
连接字符串
<connectionStrings>
<add name="AdvWorksConnection" connectionString="data source=localhost\SQLEXPRESS2014;
initial catalog=AdventureWorks2012;persist security info=True;
Integrated Security=True;"
providerName="System.Data.SqlClient" />
</connectionStrings>
你能告诉我哪里做错了吗?连接字符串有问题吗
我相信你想要这个:
<asp:sqldatasource id="CustomersSource"
selectcommand="Select [BusinessEntityID], [NationalIDNumber], [LoginID]
From [AdventureWorks2012].[HumanResources].[Employee]"
connectionstring="<%$ ConnectionStrings:AdvWorksConnection%>"
runat="server"/>
然而,AdventureWorks2012
是数据库,HumanResources
是架构,Employee
是 table。
注意:您可以删除 [AdventureWorks2012].
并且查询仍应执行,因为您的连接字符串明确表示要使用 AdventureWorks2012
数据库。