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

  • SEARCH
  • Home
  • 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 6356169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:54:47+00:00 2026-05-24T22:54:47+00:00

I have an application that saves and opens data (which is saved as SQL

  • 0

I have an application that saves and opens data (which is saved as SQL CE database file). Every time the project gets saved, a new .sdf file is generated with table structure defined by my code and I do not need to run any validation against it.

My concern is when user import (open) the .sdf file in a OpenFileDialog, there will be chance user may select a database file generated from a different application (i.e. having a different table schema). I would need to validate the importing database table schema or the application may crash if the wrong database file is opened and processed.

I do not need to compare schema between files. All I need is to check if the database file contain a certain table structure or table names (which I think should be sufficient for my purpose). What is the easiest way to do this?

[EDIT]

I used the following method to validate the database file, which works. I use a string array to checked against a SqlCeDataReader (which stores the Table name). It works but I wonder if there’s an even easier way – is there a build in method in .NET to use?

using (SqlCeConnection conn = new SqlCeConnection(validateConnStr))
{
    using (SqlCeCommand cmd = new SqlCeCommand(@"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES", conn))
    {
        try
        {
            conn.Open();
            SqlCeDataReader rdr = cmd.ExecuteReader();
            string[] tableArr = { "FirstTable", "SecondTable" };
            int ta = 0;
            while (rdr.Read())
            {
                if (rdr.GetString(0) != tableArr[ta])
                {
                    isValidDbFile = false;
                }
                else
                {
                    isValidDbFile = true;
                }
                ta++;
            }
        }
        catch (Exception ex)
        {
            //MessageBox.Show(ex.ToString());
        }
        finally
        {
            conn.Close();
        }
    }
}
  • 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-05-24T22:54:47+00:00Added an answer on May 24, 2026 at 10:54 pm

    Open the database (make sure to have error handling for this, as the user can point to any file).

    run: SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N’MyTable’

    If this returns data, your table is there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that reads a CSV file with piles of data rows.
I have an iPhone application that uses a sqlite3 database for saving data and
I have application which exports data in csv file which is stored in Document's
I have a very short Java application that just opens a connection to a
I am making a small iPhone application in which I have implemented the database
I have an Excel workbook, which using VBA code that opens another workbook, copies
I have data analysis application and I need to be able to export database
I've got a JNLP editor application that saves data to data files. I'd like
I have application that makes different queries with different results so the caching in
I have application that is connecting to the DB and if I enter incorrect

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.