由于未解析的对象引用,程序无法工作 [英] Procedure not working because of unresolved reference to object
问题描述
我正在编写一个 WPF 应用程序,在某些时候我试图通过如下程序向我的数据库添加新行:
I'm writing a WPF application where at some point I'm trying to add new row to my database through procedure like below:
CREATE PROCEDURE dbo.InsertStudent
@IdStudent INT,
@FirstName VARCHAR(50),
@LastName VARCHAR(50),
@Address VARCHAR(50),
@IndexNumber VARCHAR(50),
@IdStudies INT
AS
SET NOCOUNT ON
INSERT INTO [dbo].[apbd.Student]
([IdStudent]
,[FirstName]
,[LastName]
,[Address]
,[IndexNumber]
,[IdStudies])
VALUES
(@IdStudent
,@FirstName
,@LastName
,@Address
,@IndexNumber
,@IdStudies)
但是每当我要使用它时,我都会收到错误:
but whenever I'm about to use it, I'm getting error:
SQL71502:过程:[dbo].[InsertStudent] 有一个未解析的对对象 [dbo].[apbd.Student] 的引用.
SQL71502: Procedure: [dbo].[InsertStudent] has an unresolved reference to object [dbo].[apbd.Student].
我正在寻找解决方案,但我发现只是通过右键单击引用"等添加对数据库的引用,但我的解决方案资源管理器中没有此选项.
I was looking for solution but what I've found was only to add reference to database through right click on References and so on, but I do not have this option in my solution explorer.
也许我在错误的地方寻找它,但右键单击后我唯一的选择是这样的:
Maybe I'm looking for it in wrong places but the only options I have after right click are something like this:
- 添加参考...
- 添加对服务的引用...
- 添加连接/串联/累积(或者应该翻译)服务
- 添加分析器...
- 管理 NuGet 数据包...
至于在数据库中创建表背后的代码:
as for the code behind creation of the tables in database:
CREATE SCHEMA apbd;
GO
-- tables
-- Table: Student
CREATE TABLE apbd.Student (
IdStudent int NOT NULL IDENTITY,
FirstName nvarchar(100) NOT NULL,
LastName nvarchar(100) NOT NULL,
Address nvarchar(100) NOT NULL,
IndexNumber nvarchar(50) NOT NULL,
IdStudies int NOT NULL,
CONSTRAINT Student_pk PRIMARY KEY (IdStudent)
);
-- Table: Student_Subject
CREATE TABLE apbd.Student_Subject (
IdStudentSubject int NOT NULL IDENTITY,
IdStudent int NOT NULL,
IdSubject int NOT NULL,
CreatedAt datetime NOT NULL,
CONSTRAINT Student_Subject_pk PRIMARY KEY (IdStudentSubject,IdStudent,IdSubject)
);
-- Table: Studies
CREATE TABLE apbd.Studies (
IdStudies int NOT NULL IDENTITY,
Name nvarchar(100) NOT NULL,
CONSTRAINT Studies_pk PRIMARY KEY (IdStudies)
);
-- Table: Subject
CREATE TABLE apbd.Subject (
IdSubject int NOT NULL IDENTITY,
Name nvarchar(100) NOT NULL,
CONSTRAINT Subject_pk PRIMARY KEY (IdSubject)
);
-- End of file.
推荐答案
默认情况下,MS SQL Server 数据库只有一个架构 (dbo).您可以添加架构以出于安全或组织目的对事物进行分组.
A MS SQL Server database, by default, only has a single schema (dbo). You can add schemas to group things for either security or organizational purposes.
在您的情况下,架构 apbd 已创建,并且 Student 是在该架构上创建的,而不是 dbo 架构.因此,要引用该表,您需要使用 [apbd].[Student].
In your case, the schema apbd was created and Student was created on that schema not the dbo schema. So, to reference that table, you need to use [apbd].[Student].
这篇关于由于未解析的对象引用,程序无法工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!