Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8520025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:25:04+00:00 2026-06-11T06:25:04+00:00

Basically, I have a LINQ database context and its model. As usually, I create

  • 0

Basically, I have a LINQ database context and its model. As usually, I create the DB in the SQL context if the DB does not exist (the context is a singleton and on every access to it, this is checked).

Everything works well if I add data to the DB on the first launch. But if I don’t insert any data during the first start of the app, on successive launches I get

SqlCeException:The specified table does not exist [TableName]

I don’t know how more specifically I can explain it, but the exception comes immediately whenever I do a LINQ query on the second launch of the app if I don’t insert any data on the first launch. If i do insert some data during the first launch, all is fine for the rest of the app’s life time. Why would it be a bad thing to create the DBs and introduce the DB context, but not insert any data?

Here’s my LINQ DB model:

  • https://github.com/kypeli/Podcatcher/blob/master/wp7/Podcatcher/ViewModels/PodcastSubscriptionModel.cs

Here’s where I get the exception on second start if I didn’t insert any data on the first launch:

  • https://github.com/kypeli/Podcatcher/blob/master/wp7/Podcatcher/PodcastSqlModel.cs#L64

It also strikes me that there’s no API call to check if a table exists or not in LINQ, so I would have to assume “this should just work” – but it doesn’t.

Any ideas? Thanks! 🙂

Update: I verified analyzing the .sdf file that indeed there are no tables created if I don’t insert any data upon first launch of the app. As I see it:

  • This is a bug in LINQ-to-SQL. It should not crash if there are no tables present, but know that it should create them. Or deal with the case and create tables only when data is inserted.
  • I would need to insert some dummy data into SQL always on first launch, or…
  • Check if a table exists, if not, react to it by forcing LINQ-to-SQL to create them. But how?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:25:06+00:00Added an answer on June 11, 2026 at 6:25 am

    I’ve dealt with this problem also, I’ve fixed it this way:

    get the data context:

    dbDataContext = new DBDataContext(DBConnectionString);
    
    if( dbDataContext.DatabaseExists() == true)
    

    //then try to get an entity:

    System.Data.Linq.Table<Entity> entities = dbDataContext.Tablename;
    

    //try to get an element from the entity:

    IEnumerator<Entity> enumEntity = entities.GetEnumerator();
    

    entities.GetEnumerator(); will always raise the exception “Table not found.”

    Just use a try/catch and in the catch scope delete the db and recreate it, because your DB is empty anyway 🙂

    dbDataContext.DeleteDatabase();
    dbDataContext.CreateDatabase();
    dbDataContext.SubmitChanges();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I wanted to have an if-else statement in my linq to sql statement.
I have an issue with LINQ in vb.net. Basically I want create LEFT JOIN
i am trying to do a groupby in linq, basically i have a list
can anyone help?, i am stuck with a linq query.. basically i have a
I have been using LINQ with compiled queries, basically passing into the compiled query
Can I have some help in improving this linq. I'm basically returning speakers from
I'm wondering if its possible to join together IEnumerable's. Basically I have a bunch
I have an issue building a fairly hefty linq query. Basically I have a
I have these below LINQ to SQL queries var kayitlarFiltreli = from rows in
How do i put a nested insert into database using Linq to SQL my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.