I have an SQL Server database and I have just added a new table:-
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]
I drag the new table from the Database Explorer in Visual Web Developer into the my_schema.dbml
design window. This creates for me a my_schema.vb
file thus:-
Partial Class my_schemaDataContext
End Class
although some trace of the table does appear in the 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>
I then try to insert rows into the table like this:-
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
This results in an exception Invalid Object Name 'dbo.my_table
.
Presumably I have to jam the schema name in somewhere but can't see how to do this. I tried adding Initial Catalogue=my_schema;
to the connection string but this resulted in an exception Keyword Not Supported: Initial Catalogue
.
Has anyone any idea what else I could try? (I should note that I have also tried other tables in the same schema with the same results, which I hope would eliminate the possibility of random typos causing the problem.)