Invalid object name dbo.Images

Cliff Estes 1 Reputation point
2022-11-29T22:20:44.777+00:00

Database:
aspnet-BorrowedLightImages2022-31ddfd69-3493-469b-8cb0-3f0d286226b2; (Name copied from connectionstring)
aspnet-BorrowedLightImages2022-31ddfd69-3493-469b-8cb0-3f0d286226b2 (Name copied from SSMS)
aspnet-BorrowedLightImages2022-31ddfd69-3493-469b-8cb0-3f0d286226b2 (Name copied from VS2022 Server Object Explorer)

contains a table, dbo.Image   

SQL for that table:

CREATE TABLE [dbo].[Image] (  
	[Id]          INT            IDENTITY (1, 1) NOT NULL,  
	[ImgName]     NVARCHAR (MAX) NOT NULL,  
	[ImgPath]     NVARCHAR (MAX) NOT NULL,  
	[ImgKeywords] NVARCHAR (MAX) NOT NULL,  
	CONSTRAINT [PK_Image] PRIMARY KEY CLUSTERED ([Id] ASC)  

);

Connection string

Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=aspnet-BorrowedLightImages2022-31ddfd69-3493-469b-8cb0-3f0d286226b2;Integrated Security=True;Connect 	Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False  

SQL INSERT statement that throws the error:
"INSERT INTO dbo.Image (ImgName, ImgPath, ImgKeywords) VALUES ('1.jpg','Images\Slider','')"

Exception message
Invalid object name 'dbo.Image'

The INSERT query runs fine in SSMS.

I've tried surrounding "dbo" and "Image" with brackets thusly:
[dbo].[Image]
``to no avail.

Developer technologies | .NET | Other
SQL Server | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Cliff Estes 1 Reputation point
    2022-11-30T01:42:55.847+00:00

    Resolved.

    Somehow the connectionstring was pointing to

    initial catalog=master

    I can't count how many times I checked the cs.

    Grrrr.

    Thx for the help.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.