2

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.)

2 Answers 2

8

It looks like the connection string is incorrect. Also I believe Catalogue should be spelt at Catalog.

Sign up to request clarification or add additional context in comments.

1 Comment

Groan. That's it. Correcting Catalogue to Catalog fixes it. Thanks.
0

The constructor of your DataContext takes a connection string.

"Integrated Security=SSPI; "

doesn't look like a valid connection string to me.

If you give nothing, it will take the connection string set at the creation. Here it is the setting my_schemaConnectionString. So just do:

db = New my_schemaDataContext()

Or if you want to change it at runtime:

string connectionString = "whatever";
db = New my_schemaDataContext(connectionString)

1 Comment

this will explain all about the Integrated Security= part

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.