Click here to Skip to main content
13,200,729 members (52,860 online)
Rate this:
Please Sign up or sign in to vote.
See more: , +
Does anyone have any advice on why when I execute a program in Visual Studio 2012 my SQL Server CE local instance keeps losing connection? It's connected while I'm working in designer or code-behind, but when I execute the program to run it, I see a red X next to the database instance.
Posted 18-Sep-12 6:28am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Heads up, I got it working.

On VS2012 Add Reference, you have to browse and look for;
C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0\Desktop
and select,
Note, the above was for SQLCE 4.0. More details below.

Import it on your project and you're good to go. Just make sure you're importing the right version for the database you are using.

C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0\Desktop

C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Desktop
joshrduncan2012 18-Sep-12 13:53pm
Ok, thanks! I'll try that now.
joshrduncan2012 18-Sep-12 13:57pm
How do you import it after adding the reference?
Aron Jay 18-Sep-12 14:06pm
VB: Imports System.Data.SqlServerCe
C#: Using System.Data.SqlServerCe;
Aron Jay 18-Sep-12 14:07pm
VB: Imports.System.Data.SqlServerCe
C#: Using System.Data.SqlServerCe;
joshrduncan2012 18-Sep-12 14:07pm
Did you get the CE database connection to stick after you executed the program?
Aron Jay 18-Sep-12 14:08pm
Yes, it's working now.
joshrduncan2012 18-Sep-12 14:07pm
Everything works fine for me, I just can't keep the connection in tact after executing the program.
Aron Jay 18-Sep-12 14:09pm
What do you mean, can't keep intact?
joshrduncan2012 18-Sep-12 14:10pm
Every time I execute the program, the connection breaks after running it.
Aron Jay 18-Sep-12 14:11pm
Does it generate unhandled expression? Can you paste the error message?
joshrduncan2012 18-Sep-12 14:14pm
No unhandled exceptions, just can't view the existing code through the comboboxes in the program. :(
Aron Jay 18-Sep-12 14:16pm
*I meant exceptions. Do you have records on the you are accessing?
joshrduncan2012 18-Sep-12 14:17pm
I have a full database, I just can't access it through my program. I can only insert new data.
Aron Jay 18-Sep-12 14:20pm
Can you paste your code for combobox, on where you are having a problem? and how do you read data from sqlce? It should be SqlCeDataReader
joshrduncan2012 18-Sep-12 14:23pm
I've got 10 listeners between the 5 comboboxes right now. 2 listeners per box. Here is basically the idea of what I'm doing.

SqlCeDataReader make_dr = make_comm.ExecuteReader();
while (make_dr.Read())
// Fills make combobox with results from query
catch (SqlCeException ex)
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
Aron Jay 18-Sep-12 14:27pm
Have you tried cleaning your project and rebuilding it and also make sure you do Synchronize your project settings, it's where your connection string is stored.

Sorry dude, I don't know the specifics of your problem. This is how far I can go.
Aron Jay 18-Sep-12 14:28pm
Well, perhaps you could rate my solution for sqlce. Good luck.
joshrduncan2012 18-Sep-12 14:29pm
Thanks dude! Big help!
Member 2051651 13-May-13 10:49am
Thank you someone thats knows what there are doing.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Same here. Even after I do Imports System.Data.SqlServerCe, sqlceconnection, sqlcecommand and others are not available.
joshrduncan2012 18-Sep-12 13:02pm
You need to connect the CE database first before importing the library for it. Without the CE db in the project, you won't get sqlceconnection, et al.
Aron Jay 18-Sep-12 13:06pm
I did. Previously I was fine with 3.5 but upon updating Visual Studio 2012 Express and SQL CE 4.0, it seems that 3.5 SQL CE database is not supported on design time. So I created another database (4.0 SQLCE). There's something wrong with either VS2012 or .net 4
Aron Jay 18-Sep-12 13:07pm
Btw, my SqlServerCe.dll was from GAC folder on Microsoft.Net inside Windows folder.
Aron Jay 18-Sep-12 13:08pm
If this will never work I might consider just installing the required 3.5 components for visual studio 2012 to use my old SQL CE 3.5 database.
joshrduncan2012 18-Sep-12 13:10pm
I'm starting to believe you. :( How are you installing the 3.5 components? .net 3.5?
Aron Jay 18-Sep-12 13:12pm
Haven't done it yet. Still looking for solution on how I could get this 4.0 CE to work. How about you? *Well, I guess this is the problem for early adopters.
joshrduncan2012 18-Sep-12 13:14pm
I think I'm going to get a VM set up with Windows 7 or Windows Server 2008 and load Visual Studio 2010 on it.
Aron Jay 18-Sep-12 13:20pm
Sounds great. But I'm trying out SQL CE 3.5 on VS2012 now. I'll report back for compatibility. I believe it should. :)
joshrduncan2012 18-Sep-12 13:22pm
How are you obtaining the .net 3.5 necessities?
Aron Jay 18-Sep-12 13:30pm
microsoft download center.
Aron Jay 18-Sep-12 13:34pm
somehow i can't find it there.
Aron Jay 18-Sep-12 13:38pm
It looks like VS2012 is useless for SQLCE 4 db. When I tried to create a new project and add database, the reference it included was in fact version 3.5 of sql ce instead of 4.0. So that's why it's not working at all. I wasted my time uninstalling VS2010 on my desktop and laptop and installing this useless crap.
joshrduncan2012 18-Sep-12 13:35pm
joshrduncan2012 18-Sep-12 13:40pm
Great. Thanks for the heads up. I'm getting a VM up with Visual Studio 2010 right now. :(
Aron Jay 18-Sep-12 13:43pm
I should get my VS2010 back. Good luck.
joshrduncan2012 18-Sep-12 13:44pm
Thanks! :( I sure hope I can get this working before my boss returns on Friday.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171020.1 | Last Updated 18 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100