Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 7:28am
Rate this: bad
good
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,
System.Data.SqlServerCe.dll
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.
 
SQLCE 4.0
C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0\Desktop
 
SQLCE 3.5
C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Desktop
  Permalink  
v2
Comments
joshrduncan2012 at 18-Sep-12 13:53pm
   
Ok, thanks! I'll try that now.
joshrduncan2012 at 18-Sep-12 13:57pm
   
How do you import it after adding the reference?
Aron Jay at 18-Sep-12 14:06pm
   
VB: Imports System.Data.SqlServerCe
C#: Using System.Data.SqlServerCe;
Aron Jay at 18-Sep-12 14:07pm
   
VB: Imports.System.Data.SqlServerCe
C#: Using System.Data.SqlServerCe;
joshrduncan2012 at 18-Sep-12 14:07pm
   
Did you get the CE database connection to stick after you executed the program?
Aron Jay at 18-Sep-12 14:08pm
   
Yes, it's working now.
joshrduncan2012 at 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 at 18-Sep-12 14:09pm
   
What do you mean, can't keep intact?
joshrduncan2012 at 18-Sep-12 14:10pm
   
Every time I execute the program, the connection breaks after running it.
Aron Jay at 18-Sep-12 14:11pm
   
Does it generate unhandled expression? Can you paste the error message?
joshrduncan2012 at 18-Sep-12 14:14pm
   
No unhandled exceptions, just can't view the existing code through the comboboxes in the program. :(
Aron Jay at 18-Sep-12 14:16pm
   
*I meant exceptions. Do you have records on the you are accessing?
joshrduncan2012 at 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 at 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 at 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.
 
try
{
SqlCeDataReader make_dr = make_comm.ExecuteReader();
while (make_dr.Read())
{
// Fills make combobox with results from query
makeComboBox.Items.Add(make_dr["make"]);
}
}
catch (SqlCeException ex)
{
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Aron Jay at 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 at 18-Sep-12 14:28pm
   
Well, perhaps you could rate my solution for sqlce. Good luck.
joshrduncan2012 at 18-Sep-12 14:29pm
   
Thanks dude! Big help!
Member 2051651 at 13-May-13 10:49am
   
Thank you someone thats knows what there are doing.
Rate this: bad
good
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.
  Permalink  
Comments
joshrduncan2012 at 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 at 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 at 18-Sep-12 13:07pm
   
Btw, my SqlServerCe.dll was from GAC folder on Microsoft.Net inside Windows folder.
Aron Jay at 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 at 18-Sep-12 13:10pm
   
I'm starting to believe you. :( How are you installing the 3.5 components? .net 3.5?
Aron Jay at 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 at 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 at 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 at 18-Sep-12 13:22pm
   
How are you obtaining the .net 3.5 necessities?
Aron Jay at 18-Sep-12 13:30pm
   
microsoft download center.
Aron Jay at 18-Sep-12 13:34pm
   
somehow i can't find it there.
Aron Jay at 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 at 18-Sep-12 13:35pm
   
http://www.microsoft.com/en-us/download/confirmation.aspx?id=5783
joshrduncan2012 at 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 at 18-Sep-12 13:43pm
   
I should get my VS2010 back. Good luck.
joshrduncan2012 at 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
0 Marcin Kozub 330
1 OriginalGriff 256
2 Sergey Alexandrovich Kryukov 215
3 Praneet Nadkar 197
4 Richard MacCutchan 182
0 OriginalGriff 8,048
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 18 Sep 2012
Copyright © CodeProject, 1999-2014
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