1
votes

Have created two table 'UserShoppingItems' & 'UserShoppingBills' both in Azure database and local database (sqlexpress 2008 r2). I had manually created entity mapping for the tables using dbcontext class (not used ado.net entity database wizard) like 'UserShoppingItem' and mapping with the following code.

"public DbSet<UserShoppingItem> UserShoppingItems {get; set;}"

I could see that table exists in both local and azure server, but when I was running the site from azure, got an error message

Invalid object'dbo.UserShoppingItems'and Invalid column name 'ShopId' from 'dbo.UserShoppingBills'.

The site is built using asp.net mvc 4 and entity framework 6.1.*. Entity framework has correctly guessed the name of the table but it could not find it. Even I have tested the azure database with my local web server from visual studio, queried the database from SSMS all are working fine except when running the site from azure web server. Please help me identify the bottleneck of the issue.

EDIT:

public class UserShoppingItem
    {
       [Key]     
       [System.ComponentModel.DataAnnotations.Schema.Column(Order=0)]   
       public Int64 UserId { get; set; }
       [Key]
       [System.ComponentModel.DataAnnotations.Schema.Column(Order=1)]
       public Int64 ShopId { get; set; }       
       public int? ItemId { get; set; }        

    }

Azure DB Server - Connection string

As I have not used ado.net entity data model wizard to generate entities there is no need for use metadata=res:///xxx.csdl|res:///xxx.ssdl|res://*/xxx.msl;

<add name="xxxx" providerName="System.Data.SqlClient" connectionString="Data Source=tcp:xxxx.database.windows.net,1433;Initial Catalog=xxxxx_Test;User ID=xxxx@xxxx;Password=xxxxxx;MultipleActiveResultSets=True" />  

Local DB Server - Connection String

<add name="xxxx" providerName="System.Data.SqlClient" connectionString="Data Source=.\sqlexpressr2,49454;Initial Catalog=MappedGeoDatabase-Dev;User ID=xxxx;Password=xxxx"/>
2
show your connection strings - both for the local and for Azure DB (strip username / password info). Also post the code for UserShoppingItem class.astaykov
@astaykov please find the edit. ThanksMurugan Durai

2 Answers

1
votes

My azure websites are linked with databases. I have two websites in azure one for live and the other for testing. When I have created the test website, I had linked it with live database in azure as I don't have test database that time. I have got this issue because my live database don't have my new tables. Solution: I linked my test site with test db in azure and got its working fine now. Learned a nice lesson that irrelevant to your connection string in web.config file, you need to link your site with appropriate db in azure.

0
votes

Based on the new information :) lets change the answer.

Are you using the connection string variables in the website config?

This will let you connect both test website and live website to the same database.