简体   繁体   English

如何从C#连接到SQL Server Ce数据库?

[英]How to connect to SQL Server Ce database from C#?

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 如何将Sql Server CE Db连接到C#DotNet 4.0我听说过System.Data.SqlServerCe NameSpace用于连接本地数据库,但我无法在.Net 4.0中找到它

is there any alternate Class? 有没有替代班级?

You need to have included the System.Data.SqlServerCe namespace 您需要包含System.Data.SqlServerCe命名空间

Its in the System.Data.SqlServerCe.dll 它在 System.Data.SqlServerCe.dll

If that namespace doesn't show up then probably you haven't included refrence to that dll . 如果该命名空间没有显示,那么可能你没有包含对该dll

Add a reference to that dll and it should be available. 添加对该dll的引用,它应该可用。

If you are still having problem then check out its in GAC . 如果您仍然遇到问题,请在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. 一些答案已经提到过如何使用它。

You need the System.Data.SqlServerCe namespace. 您需要System.Data.SqlServerCe命名空间。

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

From MSDN : 来自MSDN

Namespace: System.Data.SqlServerCe 命名空间: System.Data.SqlServerCe

Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll) 程序集: System.Data.SqlServerCe(在system.data.sqlserverce.dll中)

Open Package Manager Console in Visual Studio to install it from NuGet. 在Visual Studio中打开包管理器控制台以从NuGet安装它。 Type: Install-Package SQLCE 键入:Install-Package SQLCE

Add using System.Data.SqlServerCe; using System.Data.SqlServerCe;添加using System.Data.SqlServerCe; to your class 到你的班级

And than use it like: 而不是使用它:

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

我认为你正在寻找System.Data.SqlServerCe

You can reference System.Data.SqlServerCe.dll from the .NET 2.0-3.5 GAC: 您可以从.NET 2.0-3.5 GAC引用System.Data.SqlServerCe.dll

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. 它不在.NET 4.0 GAC( C:\\Windows\\assembly\\GAC_MSIL )中,因为从2.0开始它可用于所有.NET框架。

Thanks For Your Help guys. 谢谢你的帮助。 I found Reference Dll form C:\\Program Files\\Microsoft SQL Server Compact Edition\\v3.5\\Desktop 我找到了C:\\ Program Files \\ Microsoft SQL Server Compact Edition \\ v3.5 \\ Desktop的 Reference Dll

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM