我有一个 SQL Server 数据库,我刚刚添加了一个新表:-
CREATE TABLE [dbo].[my_table](
[my_primary_key] [int] NOT NULL,
[my_data_value] [int] NULL,
PRIMARY KEY CLUSTERED
(
[my_primary_key] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
我将新表从 Visual Web Developer 中的数据库资源管理器拖到my_schema.dbml
设计窗口中。这为我创建了一个my_schema.vb
文件:-
Partial Class my_schemaDataContext
End Class
尽管该表的一些痕迹确实出现在 XML 中:-
<?xml version="1.0" encoding="utf-8"?><Database Name="my_schema" Class="my_schemaDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
<Connection Mode="AppSettings" ConnectionString="Data Source=MYPC;Initial Catalog=my_schema;Integrated Security=True" SettingsObjectName="MyProgram.My.MySettings" SettingsPropertyName="my_schemaConnectionString" Provider="System.Data.SqlClient" />
<Table Name="dbo.my_table" Member="my_tables">
<Type Name="my_table">
<Column Name="my_primary_key" Type="System.Int32" DbType="Int NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="my_data_value" Type="System.Int32" DbType="Int" CanBeNull="true" />
</Type>
</Table>
</Database>
然后我尝试像这样将行插入表中:-
Try
db = New my_schemaDataContext("Integrated Security=SSPI; ")
Dim new_row As my_table
new_row = New my_table
new_row.my_primary_key = 1
new_row.my_data_value = 1
db.my_tables.InsertOnSubmit(new_row)
db.SubmitChanges()
Catch ex As Exception
' do something
End Try
这会导致异常Invalid Object Name 'dbo.my_table
。
大概我必须在某处堵塞模式名称,但看不到如何做到这一点。我尝试添加Initial Catalogue=my_schema;
到连接字符串,但这导致了异常Keyword Not Supported: Initial Catalogue
。
有谁知道我还能尝试什么?(我应该注意,我还尝试了相同架构中的其他表,结果相同,我希望这可以消除随机拼写错误导致问题的可能性。)