Click here to Skip to main content
Sign Up to vote bad
good
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:28


2 solutions

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  
Comments
joshrduncan2012 - 18 Sep '12 - 13:53
Ok, thanks! I'll try that now.
joshrduncan2012 - 18 Sep '12 - 13:57
How do you import it after adding the reference?
Aron Jay - 18 Sep '12 - 14:06
VB: Imports System.Data.SqlServerCe C#: Using System.Data.SqlServerCe;
Aron Jay - 18 Sep '12 - 14:07
VB: Imports.System.Data.SqlServerCe C#: Using System.Data.SqlServerCe;
joshrduncan2012 - 18 Sep '12 - 14:07
Did you get the CE database connection to stick after you executed the program?
Aron Jay - 18 Sep '12 - 14:08
Yes, it's working now.
joshrduncan2012 - 18 Sep '12 - 14:07
Everything works fine for me, I just can't keep the connection in tact after executing the program.
Aron Jay - 18 Sep '12 - 14:09
What do you mean, can't keep intact?
joshrduncan2012 - 18 Sep '12 - 14:10
Every time I execute the program, the connection breaks after running it.
Aron Jay - 18 Sep '12 - 14:11
Does it generate unhandled expression? Can you paste the error message?
joshrduncan2012 - 18 Sep '12 - 14:14
No unhandled exceptions, just can't view the existing code through the comboboxes in the program. :(
Aron Jay - 18 Sep '12 - 14:16
*I meant exceptions. Do you have records on the you are accessing?
joshrduncan2012 - 18 Sep '12 - 14:17
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:20
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:23
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 - 18 Sep '12 - 14:27
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:28
Well, perhaps you could rate my solution for sqlce. Good luck.
joshrduncan2012 - 18 Sep '12 - 14:29
Thanks dude! Big help!
Member 2051651 - 13 May '13 - 10:49
Thank you someone thats knows what there are doing.
Same here. Even after I do Imports System.Data.SqlServerCe, sqlceconnection, sqlcecommand and others are not available.
  Permalink  
Comments
joshrduncan2012 - 18 Sep '12 - 13:02
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:06
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:07
Btw, my SqlServerCe.dll was from GAC folder on Microsoft.Net inside Windows folder.
Aron Jay - 18 Sep '12 - 13:08
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:10
I'm starting to believe you. :( How are you installing the 3.5 components? .net 3.5?
Aron Jay - 18 Sep '12 - 13:12
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:14
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:20
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:22
How are you obtaining the .net 3.5 necessities?
Aron Jay - 18 Sep '12 - 13:30
microsoft download center.
Aron Jay - 18 Sep '12 - 13:34
somehow i can't find it there.
Aron Jay - 18 Sep '12 - 13:38
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:35
http://www.microsoft.com/en-us/download/confirmation.aspx?id=5783
joshrduncan2012 - 18 Sep '12 - 13:40
Great. Thanks for the heads up. I'm getting a VM up with Visual Studio 2010 right now. :(
Aron Jay - 18 Sep '12 - 13:43
I should get my VS2010 back. Good luck.
joshrduncan2012 - 18 Sep '12 - 13:44
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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 358
1 OriginalGriff 355
2 Arun Vasu 345
3 Maciej Los 208
4 Zoltán Zörgő 189
0 Sergey Alexandrovich Kryukov 9,755
1 OriginalGriff 7,559
2 CPallini 4,018
3 Rohan Leuva 3,362
4 Maciej Los 2,951


Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 18 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid