Invalid object name 'dbo.Products'.

Posts   
 
    
Qurban
User
Posts: 13
Joined: 22-Feb-2012
# Posted on: 23-Feb-2012 16:13:59   

I created project LINQ To SQL. Added relational model data i.e Northwind. I right clicked on Nortwind database in catalog explorer and clicked on Reverse-Engineer Tables to Entity Definitions. Validate and generate code. I created one solution with one website in it. Added the project created by LLBLGEN. All that stuff of referencing is done. When wrote one piece of code which is pulling product name from product table and it gives the error you are looking at.

Invalid object name 'dbo.Products'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'dbo.Products'.

Source Error:

Line 20: select p; Line 21: GridView1.DataSource = products; Line 22: GridView1.DataBind(); Line 23: } Line 24: }

Source File: c:\Projects\TestProjects\LLBGenTest\LLBLGen\WebSite1\Default.aspx.cs Line: 22

Attach zip contains, VS solution, website and LLBLGEN created project and LLBLProject as well.

Attachments
Filename File size Added on Approval
LLBLGen.rar 288,761 23-Feb-2012 16:14.14 Approved
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Feb-2012 20:50:39   

Two things:

  1. Your fetch routine should look like this:
var modelAssembly = typeof(LLBLGenNorthwindDataContext).Assembly;
var resourceStream =
    modelAssembly.GetManifestResourceStream("LLBLGenNorthwind.LLBLGenNorthwindMappings.xml");
var ctx = new LLBLGenNorthwindDataContext(XmlMappingSource.FromStream(resourceStream));
        
var products = from p in ctx.Products                   
                select p;
GridView1.DataSource = products;
GridView1.DataBind();
  1. In your connection string, put 'Northwind' instead of 'master'.
David Elizondo | LLBLGen Support Team
Qurban
User
Posts: 13
Joined: 22-Feb-2012
# Posted on: 24-Feb-2012 10:33:48   

daelmo wrote:

Two things:

  1. Your fetch routine should look like this:
var modelAssembly = typeof(LLBLGenNorthwindDataContext).Assembly;
var resourceStream =
    modelAssembly.GetManifestResourceStream("LLBLGenNorthwind.LLBLGenNorthwindMappings.xml");
var ctx = new LLBLGenNorthwindDataContext(XmlMappingSource.FromStream(resourceStream));
        
var products = from p in ctx.Products                   
                select p;
GridView1.DataSource = products;
GridView1.DataBind();
  1. In your connection string, put 'Northwind' instead of 'master'.

Thanks.. Second point solved my problem...