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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:03:41+00:00 2026-05-26T05:03:41+00:00

I’m trying to create a SQL Server Compact 4.0 database in code, and I

  • 0

I’m trying to create a SQL Server Compact 4.0 database in code, and I would like to create some system lookup tables and fill them with values.

Therefore, I have a SQL script as an embedded resource in my project, which looks like this:

CREATE TABLE SomeType
(TypeID INT NOT NULL CONSTRAINT PK_SomeType PRIMARY KEY,
 TypeDesc NVARCHAR(50) NOT NULL
)
GO

INSERT INTO SomeType(TypeID, TypeDesc) VALUES(10, 'Text for value 10')
INSERT INTO SomeType(TypeID, TypeDesc) VALUES(20, 'Text for value 20')
INSERT INTO SomeType(TypeID, TypeDesc) VALUES(30, 'Text for value 30')
INSERT INTO SomeType(TypeID, TypeDesc) VALUES(40, 'Text for value 40')
INSERT INTO SomeType(TypeID, TypeDesc) VALUES(80, 'Text for value 80')
GO

I have some code to create and initialize the SQL Server Compact database, and it boils down to this:

 using (SqlCeEngine engine = new SqlCeEngine(connectionString))
 {
      engine.CreateDatabase();
      CreateInitialDatabaseObjects(connectionString);
 }

 private void CreateInitialDatabaseObjects(string connectionString)
 {
     using (SqlCeConnection conn = new SqlCeConnection(connectionString))
     {
         List<string> resourceNames = new List<string>(Assembly.GetAssembly(typeof(DatabaseInterface)).GetManifestResourceNames());
         resourceNames.Sort();

         List<string> scripts = new List<string>();

         foreach (string scriptName in resourceNames)
         {
             Stream dbScript = Assembly.GetAssembly(typeof(DatabaseInterface)).GetManifestResourceStream(scriptName);

             if (dbScript != null)
             {
                 string contents = new StreamReader(dbScript).ReadToEnd();

                 string[] splitContents = contents.Split(new string[] {"GO"}, StringSplitOptions.RemoveEmptyEntries);

                 foreach (string split in splitContents)
                 {
                     scripts.Add(split);
                 }
             }
         }

         SqlCeCommand cmd = new SqlCeCommand();
         cmd.Connection = conn;

         conn.Open();

         foreach (string script in scripts)
         {
             cmd.CommandText = script;
             cmd.ExecuteNonQuery();
         }

         conn.Close();
      }
  }

So this code basically enumerates all the embedded SQL scripts and reads them, and then splits that contents on the GO keyword into sub-scripts, which are then executed in turn.

Works fine – at least for the CREATE TABLE statements….

But SQL Server Compact 4.0 chokes on the multiple inserts…. I’ve tried to add semicolons after each INSERT line, no luck – still chokes.

The details of the error are:

System.Data.SqlServerCe.SqlCeException was unhandled
Message=There was an error parsing the query. [ Token line number = 4,Token line offset = 1,Token in error = INSERT ]
Source=SQL Server Compact ADO.NET Data Provider
ErrorCode=-2147467259
HResult=-2147217900
NativeError=25501

When I put a GO statement between each INSERT statement, it works – but if I have tables that needs hundreds of rows to be inserted, that gets a bit messy…..

Is there any tricks / method to make SQL Server Compact accept and handle multiple insert statements in a single SQL statement block??

  • 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-26T05:03:42+00:00Added an answer on May 26, 2026 at 5:03 am

    There is no magic trick, only GO or similar. You CAN only execute a single statement at a time with SQL Server Compact. My tools can generate the SQL Compact statements for you from an existing db, or you can maybe use SqlCeBulkCopy for fast data loading.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have some data like this: 1 2 3 4 5 9 2 6
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.