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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:58:02+00:00 2026-05-22T18:58:02+00:00

[EDITED – with answer] Following is my code to create SQL CE database programmatically:

  • 0

[EDITED – with answer]

Following is my code to create SQL CE database programmatically:

/* get the Path */
var directoryName = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
var fileName = System.IO.Path.Combine(directoryName, "Foo2Database.sdf");

/* check if exists */
if (File.Exists(fileName))
    File.Delete(fileName);

string connStr = @"Data Source = " + fileName;

/* create Database */
SqlCeEngine engine = new SqlCeEngine(connStr);
engine.CreateDatabase();

/* create table and columns */
using (SqlCeConnection conn = new SqlCeConnection(connStr))
{
    using (SqlCeCommand cmd = new SqlCeCommand(@"CREATE TABLE FooTable (Foo_ID int, FooData NVARCHAR(200))", conn))
    {
        try
        {
            conn.Open();
            cmd.ExecuteNonQuery();
        }
        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-22T18:58:03+00:00Added an answer on May 22, 2026 at 6:58 pm

    I have worked with SQLCE 3.1 and SharpDevelop, Try this code and see if this is what you want:

    string connStr = "Data Source = FooDatabase.sdf; Password = SomePassword";
    
    if (File.Exists("FooDatabase.sdf")) 
        File.Delete("FooDatabase.sdf");  
    
    SqlCeEngine engine = new SqlCeEngine(connStr); 
    engine.CreateDatabase();
    
    SqlCeConnection conn = null;
    
    
    try 
    {
        conn = new SqlCeConnection(connStr);
        conn.Open();
    
        SqlCeCommand cmd = conn.CreateCommand();
        cmd.CommandText = "CREATE TABLE FooTable(col1 int, col2 ntext)";
        cmd.ExecuteNonQuery();
    }
    catch 
    {
    
    }
    finally 
    {
        conn.Close();
    }
    

    Note that the database is just a file, so you can check if the database exists by looking if the file exists, also you can delete the database by deleting the file. Hope this helps.

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

Sidebar

Related Questions

Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
edited, this is it function handleDate( timestamp ) { var n=new Date(), t, ago
Edited: (after seeing Luke's answer) I'm looking to develop a website and all the
Edited........ sorry Sir I was referring this piece of code from Stephen Toub's article..
Edited Now my code is like this: #!/usr/bin/perl # import packages use Net::POP3; use
Edited:- Updated One What's wrong with this code. Now I am getting error on
Edited Question : I am working on a multithreaded JMS receiver and publisher code
EDITED and refined my question after Johannes's valuable answer bool b = true; volatile
Edited in a feeble attempt to clarify. The system converts XML into another XML
[EDITED: I left the original question below, with some more context and code to

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.