4

How to Connect Sql Server CE Db to C# DotNet 4.0 I've Heard of System.Data.SqlServerCe NameSpace for Connecting local database but i am unable to find it in .Net 4.0

is there any alternate Class?

6 Answers 6

9

You need to have included the System.Data.SqlServerCe namespace

Its in the System.Data.SqlServerCe.dll

If that namespace doesn't show up then probably you haven't included refrence to that dll.

Add a reference to that dll and it should be available.

If you are still having problem then check out its in GAC. (On my system its here:
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Data.SqlServerCe.Entity\v4.0_4.0.0.0__89845dcd8080cc91

Some answers have already mentioned how to use it.

Sign up to request clarification or add additional context in comments.

3 Comments

I have added Refrence to the assembly .. But now I am not having any SqlCe Class .. :S
Ummm not sure what you mean by that.. but In System.Data.SqlServerCe namespace we have SqlCeConnection, SqlCeDataReader, SqlCeDataAdapter.. and many other classes but no SqlCe class...
If using the PowerCommands in VS2010, note that the dll appears in the Assemblies list, but in the "Extensions" sub-section rather than "Framework" (cleverly hidden "tabs" on the left side of the dialog).
4

You need the System.Data.SqlServerCe namespace.

SqlCeConnection conn = new SqlCeConnection("Data Source=\\Mobile\\Northwind.sdf;");
conn.Open();
.
.
.
conn.Close();

From MSDN:

Namespace: System.Data.SqlServerCe

Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)

1 Comment

Did you add reference to this assembly?
4

Open Package Manager Console in Visual Studio to install it from NuGet. Type: Install-Package SQLCE

Add using System.Data.SqlServerCe; to your class

And than use it like:

using (var connection = new SqlCeConnection("someConnectionString"))
{
    //do stuff
}

3 Comments

Where to Open Package Manager Console .. ^_^
If you have Visual Stuidio 2010, look for it in View>Other Windows
I'm getting 'unable to find package sqlce' Any ideas?
2

I think you are looking for System.Data.SqlServerCe.

Comments

1

You can reference System.Data.SqlServerCe.dll from the .NET 2.0-3.5 GAC:

c:\Windows\assembly\GAC_MSIL\System.Data.SqlServerCe\4.0.0.0__89845dcd8080cc91\System.Data.SqlServerCe.dll

It is not in the .NET 4.0 GAC (C:\Windows\assembly\GAC_MSIL) because it is available for all .NET frameworks since 2.0.

Comments

0

Thanks For Your Help guys. I found Reference Dll form C:\Program Files\Microsoft SQL Server Compact Edition\v3.5\Desktop

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.