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 7749639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:05:34+00:00 2026-06-01T11:05:34+00:00

Just wondering about some practice about this; I have made a simple visual C#

  • 0

Just wondering about some practice about this;

I have made a simple visual C# program with local database (SQL CE) (dB.sdf file).

Let’s say user deletes the dB.sdf file and try to open the exe program – nothing happens (the exe file starts but closes again).

What’s the typically practice here? Is it that the program just won’t start or is it to make the program create a database file if it doesn’t exists?

If it is the latter, how is it done?

  • 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-01T11:05:35+00:00Added an answer on June 1, 2026 at 11:05 am

    The second approach is more wise as your program is uselsess if it depends on database which gets deleted.

    string connStr = "Data Source = DBName.sdf; Password = DBPassword";  
    
    if (!File.Exists("DBName.sdf")){
    
    try  {     
    SqlCeEngine engine = new SqlCeEngine(connStr);  
    engine.CreateDatabase();  
    
    SqlCeConnection conn = new SqlCeConnection(connStr);     
    conn.Open();      
    
    SqlCeCommand cmd = conn.CreateCommand();     
    cmd.CommandText = "CREATE TABLE TableName(Col1 int, Col2 varchar(20))";     
    cmd.ExecuteNonQuery(); 
    
    } 
    catch (SQLException ex){
        // Log the exception
    } 
    finally  {     
    conn.Close(); 
    }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering how people would go about this. Say I have one class that
Just wondering about this... I have several separate javascript files, that all contain code
Just trying to canvas some opinions here. I was wondering how people go about
Just wondering about this code below... when I turn off my internet connection and
I was just wondering about something. I have a frame that loads pages and
Was just wondering about DependencyProperties. Usually I'm seeing this kind of coding standard when
Just wondering about how to avoid Magic Strings in Querystrings? I have a lot
I am wondering about CI best practices I need to have some code that
I've been wondering about this for some time now. In the game Angry Birds
Just wondering about this, is it possible to use Django with the Google Apps

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.